Filtering two fields from one form - Please Help!

G

Guest

All,

as a Novice I am looking at trying to get a forn to Open up using this
criteria.

Date & Route. but the wizard only allows me to select only one. I have
played with it and just dont understand why I am getting a "Mismatch" error.

any ideas?

-The Novice

Private Sub Command20_Click()
On Error GoTo Err_Command20_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Frm_PPL_Main"

stLinkCriteria = "[RouteID]=" & "'" & Me![RouteID] & "'" And "[Date]=" &
"#" & Me![Date] & "#"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command20_Click:
Exit Sub

Err_Command20_Click:
MsgBox Err.Description
Resume Exit_Command20_Click

End Sub
 
D

Douglas J Steele

Your AND statement must be inside of the quotes:

stLinkCriteria = "[RouteID]='" & Me![RouteID] & "' And [Date]=#" &
Me![Date] & "#"

As well, what datatype is RouteID? The way you've got it written, it must be
Text. If it's numeric, get rid of the single quotes:

stLinkCriteria = "[RouteID]=" & Me![RouteID] & " And [Date]=#" &
Me![Date] & "#"

(Note that I simplified the expression slightly, but it amounts to the same
thing you had before)
 
G

Guest

Thanks DJS, That did work. the Route ID is Text so i left the Squote in.

Thanks again!

Douglas J Steele said:
Your AND statement must be inside of the quotes:

stLinkCriteria = "[RouteID]='" & Me![RouteID] & "' And [Date]=#" &
Me![Date] & "#"

As well, what datatype is RouteID? The way you've got it written, it must be
Text. If it's numeric, get rid of the single quotes:

stLinkCriteria = "[RouteID]=" & Me![RouteID] & " And [Date]=#" &
Me![Date] & "#"

(Note that I simplified the expression slightly, but it amounts to the same
thing you had before)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


TwinDad said:
All,

as a Novice I am looking at trying to get a forn to Open up using this
criteria.

Date & Route. but the wizard only allows me to select only one. I have
played with it and just dont understand why I am getting a "Mismatch" error.

any ideas?

-The Novice

Private Sub Command20_Click()
On Error GoTo Err_Command20_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Frm_PPL_Main"

stLinkCriteria = "[RouteID]=" & "'" & Me![RouteID] & "'" And "[Date]=" &
"#" & Me![Date] & "#"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command20_Click:
Exit Sub

Err_Command20_Click:
MsgBox Err.Description
Resume Exit_Command20_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top