title: Trouble with DoCmd.OpenReport with a complicated Where Clause (Syntax Issue)
body: <p>So first I have gone over a very large amount of other sources trying to look for a solution or an explanation of my error, but I haven't found anything that helps me quite yet.</p>
  <p>I have been learning all this stuff on my own so I am definitely lacking in some of the foundation knowledge and it has caught up to me. Basically the form I am having trouble with allows the user to generate three different reports based on the kind of criteria they care about. There are three different combo boxes cboCompany, cboProject, cboEmployee. I use the Nz command to change null values to zero and then use If Statements to  determine which report to use depending on what the user selects. I hope that kind of makes since. Its easier to show than explain. That part all works fine though.</p>
  <p>The problem I'm getting is when I want to do a print preview for the report the user generates. I need the where clause to take the values the user selects to use in the print preview. I can't get the syntax right for the where clause to actually do this.</p>
  <p>Here is how I call my variables. The Nz function as I understand require the variables to be variants, because of this I'm not quite sure how to write the syntax for the where clause. I know integers, strings, and dates all have different syntax but I don't know what variant would be.</p>
  <pre><code>Dim Company As Variant
  Dim Project As Variant
  Dim Employee As Variant
  Dim EndDate As String
  Dim StartDate As String
  
  Company = Nz(cboCompany, 0)
  Project = Nz(cboProject, 0)
  Employee = Nz(cboEmployee, 0)
  StartDate = txtStartDate.Value
  EndDate = txtEndDate.Value
  </code></pre>
  <p>So this next part is how I have written one of the report options with my best guess of the syntax for the where clause. It doesn't work so If you could help point me in the right direction I would greatly appreciate it.</p>
  <pre><code> ElseIf Company &lt;&gt; 0 And Project &lt;&gt; 0 And Employee &lt;&gt; 0 Then
      DoCmd.OpenReport &quot;ProjectReport_Employee_R&quot;, acViewPreview, &quot;&quot;, &quot;[cboCompany]= &quot; &amp; Company &amp; &quot; And [cboEmployee]= &quot; &amp; Employee &amp; &quot; And [cboProject]= &quot; &amp; Project &amp; &quot; And [txtStartDate]= #&quot; &amp; StartDate &amp; &quot;# And [txtEndDate]= #&quot; &amp; EndDate &amp; &quot;#&quot;, acWindowNormal
  </code></pre>
  <p>If I don't explain things well enough or you need more code to help please let me know, and thank you in advance.</p>
  <p>***Edit: Just to give a more complete picture this is the code behind the entire form.</p>
  <pre><code>Private Sub cboCompany_AfterUpdate()
      Me.cboProject.Requery
  End Sub
  
  Private Sub cmdSubmit_Click()
      
      'Open Report With Filter Criteria
      Dim Company As Variant
      Dim Project As Variant
      Dim Employee As Variant
      
      Company = Nz(cboCompany, 0)
      Project = Nz(cboProject, 0)
      Employee = Nz(cboEmployee, 0)
      
      If Company = 0 Then
          MsgBox (&quot;Please Select At Least A Company To Generate A Report&quot;)
          cboCompany.Value = Null
          cboProject.Value = Null
          cboEmployee.Value = Null
          
      ElseIf Company &lt;&gt; 0 And Project = 0 And Employee = 0 Then
          DoCmd.BrowseTo acBrowseToReport, &quot;ProjectReport_Company_R&quot;, &quot;Main_F.NavigationSubform&gt;ProjectReport_F.Child31&quot;
      
      ElseIf Company &lt;&gt; 0 And Project &lt;&gt; 0 And Employee = 0 Then
          DoCmd.BrowseTo acBrowseToReport, &quot;ProjectReport_Project_R&quot;, &quot;Main_F.NavigationSubform&gt;ProjectReport_F.Child31&quot;
      
      ElseIf Company &lt;&gt; 0 And Project &lt;&gt; 0 And Employee &lt;&gt; 0 Then
          DoCmd.BrowseTo acBrowseToReport, &quot;ProjectReport_Employee_R&quot;, &quot;Main_F.NavigationSubform&gt;ProjectReport_F.Child31&quot;
      
      ElseIf Company &lt;&gt; 0 And Project = 0 And Employee &lt;&gt; 0 Then
          MsgBox (&quot;Please Select A Project&quot;)
          
      End If
      
  End Sub
  
  Private Sub Form_Current()
   Me.cboCompany.SetFocus
  End Sub
  
  Private Sub Form_Load()
     
  'Set Date Values
     Dim EndDate As String
     Dim StartDate As String
          StartDate = Format(DateSerial(Year(Date), Month(DateAdd(&quot;m&quot;, -1, Date)), 16), &quot;Short Date&quot;)
          EndDate = Format(DateSerial(Year(Date), Month(Date), 15), &quot;Short Date&quot;)
      
      txtStartDate.Value = StartDate
      txtEndDate.Value = EndDate
  
  'Set The Form Message on Open Child31
      DoCmd.BrowseTo acBrowseToForm, &quot;ProjectReport_Message_F&quot;, &quot;Main_F.NavigationSubform&gt;ProjectReport_F.Child31&quot;
      
     
      
  End Sub
  '------------------------------------------------------------
  ' Print_Click
  '
  '------------------------------------------------------------
  Private Sub Command39_Click()
  On Error GoTo Command39_Click_Err
  
      Dim Company As Variant
      Dim Project As Variant
      Dim Employee As Variant
      Dim EndDate As String
      Dim StartDate As String
      
      Company = Nz(cboCompany, 0)
      Project = Nz(cboProject, 0)
      Employee = Nz(cboEmployee, 0)
      StartDate = txtStartDate.Value
      EndDate = txtEndDate.Value
      
      
      If Company &lt;&gt; 0 And Project = 0 And Employee = 0 Then
      
          DoCmd.OpenReport &quot;ProjectReport_Company_R&quot;, acViewPreview, &quot;&quot;, &quot;&quot;, acNormal
          
      ElseIf Company &lt;&gt; 0 And Project &lt;&gt; 0 And Employee = 0 Then
      
          DoCmd.OpenReport &quot;ProjectReport_Project_R&quot;, acViewPreview, &quot;&quot;, &quot;&quot;, acNormal
          
      ElseIf Company &lt;&gt; 0 And Project &lt;&gt; 0 And Employee &lt;&gt; 0 Then
      
          DoCmd.OpenReport &quot;ProjectReport_Employee_R&quot;, acViewPreview, &quot;&quot;, &quot;[cboCompany]= &quot; &amp; Company &amp; &quot; And [cboEmployee]= &quot; &amp; Employee &amp; &quot; And [cboProject]= &quot; &amp; Project &amp; &quot; And [txtStartDate]= '&quot; &amp; StartDate &amp; &quot;' And [txtEndDate]= '&quot; &amp; EndDate &amp; &quot;'&quot;, acWindowNormal
      
      End If
  
  
  Command39_Click_Exit:
      Exit Sub
  
  Command39_Click_Err:
      MsgBox Error$
      Resume Command39_Click_Exit
  
  End Sub
  </code></pre>