Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Reports / Printing / July 2008

Tip: Looking for answers? Try searching our database.

More than one where condition

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Opal - 30 Jul 2008 18:27 GMT
I am attempting to open a report with more than one where condition
and I am getting a Type Mismatch error.  I can't figure out quite how
to get this to work.

Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click

   Dim stDocName As String
   Dim stWhere As String

If Len([cboFilter1] & "") <> 0 And Len([cboSearchReportsTo] & "") = 0
_
And Len([cboZone] & "") <> 0 And _
Len([cboSearchTM] & "") = 0 And Len([cboSearchDept] & "") <> 0 Then

       stWhere = ("ZoneID =" & cboZone) And ("DeptID =" &
cboSearchDept)
       DoCmd.OpenReport "rptByShop", acPreview, , stWhere

   End If

First of all, can I filter a report through a form with more than one
where condition?

The user selects "conditions" from a drop down form and the report
opens based on their selections.  I am trying to get the report to
open based on more than one where condition and cannot figure
out if this can be accomplished.  Any assistance will be appreciated.
Marshall Barton - 30 Jul 2008 19:39 GMT
>I am attempting to open a report with more than one where condition
>and I am getting a Type Mismatch error.  I can't figure out quite how
[quoted text clipped - 19 lines]
>First of all, can I filter a report through a form with more than one
>where condition?

This kind of thing is usually handled with this kind of
logic:

If Len(cboFilter1 & "") <> 0 Then
    stWhere = stWhere & " And somefield = " & cboFilter1
End If
If Len(cboSearchReportsTo & "") <> 0 Then
    stWhere = stWhere & "And tofield = " & cboSearchReportsTo
End If
If Len([cboZone] & "") <> 0 Then
    stWhere = stWhere & " And ZoneID = " & cboZone
End If
If Len([cboSearchTM] & "") <> 0 Then
    stWhere = stWhere & " And TMfield = " & cboSearchTM
End If
If Len([cboSearchDept] & "") <> 0 Then
    stWhere = stWhere & " And DeptID = " & cboSearchDept
End If

DoCmd.OpenReport "rptByShop", acPreview, , Mid(stWhere, 6)

BUT that only works for number type fields.  If a field is a
Text field, then use:

    stWhere = stWhere & " And textfield = """ & cboxxx & """"

And for a date fields:
    stWhere = stWhere & " And datefield = #" & cboyyy & "#"

Signature

Marsh
MVP [MS Access]

Opal - 30 Jul 2008 20:17 GMT
> >I am attempting to open a report with more than one where condition
> >and I am getting a Type Mismatch error.  I can't figure out quite how
[quoted text clipped - 54 lines]
>
> - Show quoted text -

Thank you, Marsh, that helps alot!  They are number fields.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.