Syntax Error

  • Thread starter Thread starter bw
  • Start date Start date
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?
 
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.
 
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
 
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.
 
Back
Top