stLinkCriteria syntax help

B

BrettS

Hi, trying to use the following code to open another form while retaining the
same [RE Job #] and [Sample #]:

Private Sub OpenMeasurement_Click()
On Error GoTo Err_OpenMeasurement_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MeasData"
stLinkCriteria = "[RE Job #]='" & Me![RE Job #] & _
" and [Sample #]=" & Me![Sample #]

DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_OpenMeasurement_Click:
Exit Sub
Err_OpenMeasurement_Click:
MsgBox Err.Description
Resume Exit_OpenMeasurement_Click
End Sub

However, when I use this code (with the values for RE Job # and Sample #
being A1226 and 2), I get this error message:
Syntax error in string in query expression '[RE Job #]='A1226 and [Sample
#]=2'.


Any help on how to fix this would be much appreciated, thank you.
 
D

Douglas J. Steele

You've forgotten to put the closing single quote (before the keyword and)"

stLinkCriteria = "[RE Job #]='" & Me![RE Job #] & _
"' and [Sample #]=" & Me![Sample #]
 

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