Compile Error and Syntax Error on Form

G

Guest

I'm trying to open a form based on informaiton from another form. I have the
following code but I keep getting a Compile error. When I take out one of
the parameters it works fine but obviously does not give me the right record.
I want to find a ProjecNumber and a WorkOrderNumber (that is my primary key
combination).
My code is:
Private Sub Open_Invoice_Click()
On Error GoTo Err_Open_Invoice_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Work Order Invoice_Solo"

stLinkCriteria = "[ProjectNumber]=" & Me![ProjectNumber] And = "[Work
Order Number]=" & Me![Work Order Number]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Open_Invoice_Click:
Exit Sub

Err_Open_Invoice_Click:
MsgBox Err.Description
Resume Exit_Open_Invoice_Click

End Sub
Thanks
 
G

Graham R Seach

Gretchen,

You'd messed it up a bit. Remember to open and close the quotes in the
correct places.

stLinkCriteria = "[ProjectNumber]=" & Me![ProjectNumber] & " And [Work
Order Number]=" & Me![Work Order Number]

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
G

Guest

Graham,
I tried this exact syntax and got the same error...any other suggestions?
thanks,
Gretchen

Graham R Seach said:
Gretchen,

You'd messed it up a bit. Remember to open and close the quotes in the
correct places.

stLinkCriteria = "[ProjectNumber]=" & Me![ProjectNumber] & " And [Work
Order Number]=" & Me![Work Order Number]

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Gretchen said:
I'm trying to open a form based on informaiton from another form. I have
the
following code but I keep getting a Compile error. When I take out one of
the parameters it works fine but obviously does not give me the right
record.
I want to find a ProjecNumber and a WorkOrderNumber (that is my primary
key
combination).
My code is:
Private Sub Open_Invoice_Click()
On Error GoTo Err_Open_Invoice_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Work Order Invoice_Solo"

stLinkCriteria = "[ProjectNumber]=" & Me![ProjectNumber] And = "[Work
Order Number]=" & Me![Work Order Number]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Open_Invoice_Click:
Exit Sub

Err_Open_Invoice_Click:
MsgBox Err.Description
Resume Exit_Open_Invoice_Click

End Sub
Thanks
 
G

Graham R Seach

Gretchen,

You can't be getting a compile error on this line. It's probable that one of
the arguments is textual, in which case a slightly different syntax is
needed. Assuming [ProjectNumber] is textual and [Work Order Number] is
numeric:

stLinkCriteria = "[ProjectNumber]=""" & Me![ProjectNumber] & """ And [Work
Order Number]=" & Me![Work Order Number]

From the above example, you can see how strings are treated. If one or the
other (or both) is actually text, you can now see what to do.

Just in case there are other errors elsewhere, from the Debug menu, select
Compile. What error is highlighted?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Gretchen said:
Graham,
I tried this exact syntax and got the same error...any other suggestions?
thanks,
Gretchen

Graham R Seach said:
Gretchen,

You'd messed it up a bit. Remember to open and close the quotes in the
correct places.

stLinkCriteria = "[ProjectNumber]=" & Me![ProjectNumber] & " And [Work
Order Number]=" & Me![Work Order Number]

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Gretchen said:
I'm trying to open a form based on informaiton from another form. I
have
the
following code but I keep getting a Compile error. When I take out one
of
the parameters it works fine but obviously does not give me the right
record.
I want to find a ProjecNumber and a WorkOrderNumber (that is my primary
key
combination).
My code is:
Private Sub Open_Invoice_Click()
On Error GoTo Err_Open_Invoice_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Work Order Invoice_Solo"

stLinkCriteria = "[ProjectNumber]=" & Me![ProjectNumber] And =
"[Work
Order Number]=" & Me![Work Order Number]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Open_Invoice_Click:
Exit Sub

Err_Open_Invoice_Click:
MsgBox Err.Description
Resume Exit_Open_Invoice_Click

End Sub
Thanks
 

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