DoCmd.OpenForm Syntax

D

DEI

I am trying to add an "And" in a where clause of the DoCmd.OpenForm (see
below), but I can't seem to get the syntax right re: the 'And'. I keep
getting a "Type Mismatch" error.

Does anyone know the right syntax?

Thanks

stDocName = "Applications"

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

DoCmd.OpenForm stDocName, , , stLinkCriteria
 
P

PC Datasheet

Your StudentID is a string data type and thus needs to be enclosed in
quotes.

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

Mark

Try this:
stLinkCriteria = "[Date] = #" & Me![Date] & "# And [StudentID] = " &
Me![StudentID]
 
F

fredg

I am trying to add an "And" in a where clause of the DoCmd.OpenForm (see
below), but I can't seem to get the syntax right re: the 'And'. I keep
getting a "Type Mismatch" error.

Does anyone know the right syntax?

Thanks

stDocName = "Applications"

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

DoCmd.OpenForm stDocName, , , stLinkCriteria

A couple of mistakes.
1) Your AND is outside of the string

If StudentID is a Number datatype:
stLinkCriteria = "[DateField]= #" & Me![DateField] & "# And
[StudentID] = " & Me![StudentID]

If StudentID is Text datatype:
stLinkCriteria = "[DateField]= #" & Me![DateField] & "# And
[StudentID]= '" &
Me![StudentID] & "'"

2) Do you really have a field named "Date" in your database table?

Date is a reserved Access/VBA/Jet word and should not be used as a
field name.
See the Microsoft KnowledgeBase article for your version of Access:

109312 'Reserved Words in Microsoft Access' for Access 97
209187 'ACC2000: Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'
321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'
 
V

Van T. Dinh

stLinkCriteria = "([Date] = #" & Me![Date] & "#) And ([StudentID] = " & _
Me![StudentID] & ")"

(assuming your Regional Settings for date is of format mm/dd/yyyy)

BTW, "Date" is not a good choice for a Field name since it is a reserved
word for the Date() function.
 

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