Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenForm with multiple criteria

Status
Not open for further replies.

mtwildtrout

Technical User
Oct 1, 2003
23
0
0
US
I want to open a form showing certain records based on information entered by the user in a data entry form. There is a command button on a data entry subform which contains the open form code. I need to only present records based on two information fields - WorkDate & EmployeeID. Part of the code I'm using is as follows:

Dim stLinkCroteria As String

stLinkCrieria = "[EmployeeID]=" & "'" & Me!EmployeeID] & "'"

DoCmd.OpenForm stdocName, acFormDS, , stLinkCriteria

This code works but when I add the second criteria with an "AND" I get a Type Mismatch error. The addtional statement I'm using is -

AND "[WorkDate]=" & "#" & Me![WorkDate] & "#"

This statement & the one above were genrated by the wizard, so I assume the coding is correct. Maybe a bad assumption?

When I use the above selection criteria individually, it works. However, when I join them together with an AND, I get a Type Mismatch error. Both date fields are formatted as short dates.

Are you limited to only one select criteria when using DoCmd.OpenForm? Is my coding of the criteria wrong? Is there another way to accomplish what I'm trying to do?
 
The AND must be part of the string - it must fall within quotes, like so:

Code:
stLinkCrieria = "[EmployeeID]='" & Me![EmployeeID] _
& "' AND [WorkDate]=#" & Me![WorkDate] & "#"

HTH...

Ken S.
 
You need to remove the " at the end of your first criteria and remove the " after the AND for the second criteria. The AND is part if the string. The way you are using it is as a boolean operator.

Hope this helps.

 
Thanks! I appreciate your help. Your suggestions have solved my problem.

Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top