Syntax Error

B

bw

I'm getting the following message:
Syntax error (missing operator) in query expression '[BankName]='Dummy Name
Int'l Bank".

This error ONLY occurs when there is an apostrophe in the bank name, as
above...AND ONLY with a specific Form. The same syntax is used for multiple
forms in my database.

The Code producing the error is as follows:
stDocName = "frmBillSeats"
stLinkCriteria = "[BankName]=" & "'" & Me![BankName] & "'"
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria

Does anyone have an idea as to what the problem may be?
 
S

Stuart McCall

bw said:
I'm getting the following message:
Syntax error (missing operator) in query expression '[BankName]='Dummy
Name Int'l Bank".

This error ONLY occurs when there is an apostrophe in the bank name, as
above...AND ONLY with a specific Form. The same syntax is used for
multiple forms in my database.

The Code producing the error is as follows:
stDocName = "frmBillSeats"
stLinkCriteria = "[BankName]=" & "'" & Me![BankName] & "'"
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria

Does anyone have an idea as to what the problem may be?

Access is treating the embedded apostrophe as the terminating delimiter.
Easily fixed:

stLinkCriteria = "[BankName]='" & Replace(Me![BankName],"'", "''") & "'"

The Replace function substitutes all single apostrophes with double
apostrophes.
 
B

bw

Stuart McCall said:
bw said:
I'm getting the following message:
Syntax error (missing operator) in query expression '[BankName]='Dummy
Name Int'l Bank".

This error ONLY occurs when there is an apostrophe in the bank name, as
above...AND ONLY with a specific Form. The same syntax is used for
multiple forms in my database.

The Code producing the error is as follows:
stDocName = "frmBillSeats"
stLinkCriteria = "[BankName]=" & "'" & Me![BankName] & "'"
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria

Does anyone have an idea as to what the problem may be?

Access is treating the embedded apostrophe as the terminating delimiter.
Easily fixed:

stLinkCriteria = "[BankName]='" & Replace(Me![BankName],"'", "''") & "'"

The Replace function substitutes all single apostrophes with double
apostrophes.
Thanks Stuart, your fixed worked just fine. However, as I said, that code I
was using works on every other form, so why not this one?

Bernie
 
S

Stuart McCall

bw said:
Stuart McCall said:
bw said:
I'm getting the following message:
Syntax error (missing operator) in query expression '[BankName]='Dummy
Name Int'l Bank".

This error ONLY occurs when there is an apostrophe in the bank name, as
above...AND ONLY with a specific Form. The same syntax is used for
multiple forms in my database.

The Code producing the error is as follows:
stDocName = "frmBillSeats"
stLinkCriteria = "[BankName]=" & "'" & Me![BankName] & "'"
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria

Does anyone have an idea as to what the problem may be?

Access is treating the embedded apostrophe as the terminating delimiter.
Easily fixed:

stLinkCriteria = "[BankName]='" & Replace(Me![BankName],"'", "''") & "'"

The Replace function substitutes all single apostrophes with double
apostrophes.
Thanks Stuart, your fixed worked just fine. However, as I said, that code
I was using works on every other form, so why not this one?

Bernie

The otherforms have not (yet) had to deal with data containing embedded
apostrophes? Other than that I have no idea.
 

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