Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My solution is below in three parts. (1) Build Query, (2) Main Form, (3) Subform. `Private Sub OpenJobsQuery() ' This sub will construct the query on the front page for the user ' based on who they are and what they select from the combo boxes above ' the table for filtering by redefining the rowsource of the subform ' subQryOpenJobs</p> <pre><code>Dim strSql As String ' Main SQL SELECT statement Dim strWhere As String ' Where clause containing user specified parameters. strSql = "SELECT * FROM tblOpenJobs" strWhere = "" ' Check to see if anything was selected from the Shift ' combo box. If so, begin the Where clause. If Not IsNull(Me.cboOpenJobShift.Value) Then strWhere = "WHERE tblOpenJobs.[Shift] = '" &amp; Me.cboOpenJobShift.Value &amp; "'" End If ' Check to see if anything was selected from the Department ' combo box. If so, append or begin the where clause. If Not IsNull(Me.cboOpenJobDepartment.Value) Then If strWhere = "" Then strWhere = "WHERE tblOpenJobs.[Department] = '" &amp; Me.cboOpenJobDepartment.Value &amp; "'" Else strWhere = strWhere &amp; " AND tblOpenJobs.[Department] = '" &amp; Me.cboOpenJobDepartment.Value &amp; "'" End If End If ' Check to see if anything was selected from the Date ' field. If so, append or begin the Where clause. If Not IsNull(Me.cboOpenJobDate.Value) Then If strWhere = "" Then strWhere = "WHERE tblOpenJobs.[JobDate] = #" &amp; Me.cboOpenJobDate.Value &amp; "#" Else strWhere = strWhere &amp; " AND tblOpenJobs.[JobDate] = #" &amp; Me.cboOpenJobDate.Value &amp; "#" End If Else ' If nothing was entered in the date field, make sure the user ' only sees future jobs. If strWhere = "" Then strWhere = "WHERE tblOpenJobs.[JobDate] &gt; #" &amp; FormatDateTime(Date, vbShortDate) &amp; "#" Else strWhere = strWhere &amp; " AND tblOpenJobs.[JobDate] &gt; #" &amp; FormatDateTime(Date, vbShortDate) &amp; "#" End If End If ' Always include as part of the where clause, a section that ' will narrow the results based on who the user is If strWhere = "" Then strWhere = "WHERE tblOpenJobs.[OpenJobID] Not In " &amp; _ "(SELECT tblSignUps.[OpenJobID] FROM tblSignUps WHERE tblSignUps.[EUID] = '" &amp; strEUID &amp; "');" Else strWhere = strWhere &amp; " AND tblOpenJobs.[OpenJobID] Not In " &amp; _ "(SELECT tblSignUps.[OpenJobID] FROM tblSignUps WHERE tblSignUps.[EUID] = '" &amp; strEUID &amp; "');" End If ' Concatenate the Select and the Where clause together strSql = strSql &amp; " " &amp; strWhere ' Set the recordsource of the subform to the SQL query generated ' and refresh the form. Me.subQryOpenJobs.Form.RecordSource = strSql ' In addition, synchronize the JobID's in the Edit Job box to match those ' filtered by this Build Query. Me.cboSelectJOBID.RowSource = "SELECT tblOpenJobs.[OpenJobID] FROM tblOpenJobs" &amp; " " &amp; strWhere Me.Refresh </code></pre> <p>End Sub`</p> <p>(2) Main Form. <a href="http://j.imagehost.org/view/0385/Form" rel="nofollow noreferrer">http://j.imagehost.org/view/0385/Form</a>. and (3) the subform is populated as shown in the BuildQuery() sub to construct the query based on what the user selects from the drop down filters and the input boxes on the right of the form. The data in the table itself is inaccessible to the user, this is just for them to reference.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload