Syntax error

A

Abay

I have a "browse" tabular form which shows critical fields for clients in a
Client table, one line per client .. each line has a "command button" to
show "More" information .. which brings up a form containing all information
for a client .. the link between the forms is the Client name.

This works fine except for a client name of, for example, O'Donnell. When
the command button is clicked for O'Donnell I get the message "Syntax error
(missing operator) in query expression '[Lname] = 'O'Donnell".

The code for the command button is as follows:

Private Sub Command150_Click()
On Error GoTo Err_Command150_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FClient_and_sub_more"

stLinkCriteria = "[Lname]=" & "'" & Me![Lname] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command150_Click:
Exit Sub

Err_Command150_Click:
MsgBox Err.Description
Resume Exit_Command150_Click

I'm sure the problem is caused by the ' as part of the name .. any help
would be much appreciated for a newbie learning as I go along ... said that
before, but I'm still learning.

abay
 
T

tina

yes, that apostrophe is probably what's causing the error, but you would
probably be better off not using a last name field as your "link" between
the forms - for instance, what happens when you have two records with last
name "Smith"?

hopefully you have a primary key field, that is not a client name, in your
Client table. the primary key/foreign key is almost always the best value to
use in finding and retrieving a specific record.

hth
 
G

Guest

Another question:
Is there a way to write a criteria and never worry about the ' or " or other
special characters?
I'm assuming that sometimes I have to compare Strings.

like in
stLinkCriteria = "[FieldName]='" & MyVar & "'"
where MyVar can include '," etc..

Thank you

tina said:
yes, that apostrophe is probably what's causing the error, but you would
probably be better off not using a last name field as your "link" between
the forms - for instance, what happens when you have two records with last
name "Smith"?

hopefully you have a primary key field, that is not a client name, in your
Client table. the primary key/foreign key is almost always the best value to
use in finding and retrieving a specific record.

hth


Abay said:
I have a "browse" tabular form which shows critical fields for clients in a
Client table, one line per client .. each line has a "command button" to
show "More" information .. which brings up a form containing all information
for a client .. the link between the forms is the Client name.

This works fine except for a client name of, for example, O'Donnell. When
the command button is clicked for O'Donnell I get the message "Syntax error
(missing operator) in query expression '[Lname] = 'O'Donnell".

The code for the command button is as follows:

Private Sub Command150_Click()
On Error GoTo Err_Command150_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FClient_and_sub_more"

stLinkCriteria = "[Lname]=" & "'" & Me![Lname] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command150_Click:
Exit Sub

Err_Command150_Click:
MsgBox Err.Description
Resume Exit_Command150_Click

I'm sure the problem is caused by the ' as part of the name .. any help
would be much appreciated for a newbie learning as I go along ... said that
before, but I'm still learning.

abay
 
A

Abay

Many thanks Tina for your reply ... actually the primary key is the last
name, so I guess the question is as stated by jouj .. is there away to
around the apostrophe ?

abay

tina said:
yes, that apostrophe is probably what's causing the error, but you would
probably be better off not using a last name field as your "link" between
the forms - for instance, what happens when you have two records with last
name "Smith"?

hopefully you have a primary key field, that is not a client name, in your
Client table. the primary key/foreign key is almost always the best value to
use in finding and retrieving a specific record.

hth


Abay said:
I have a "browse" tabular form which shows critical fields for clients
in
a
Client table, one line per client .. each line has a "command button" to
show "More" information .. which brings up a form containing all information
for a client .. the link between the forms is the Client name.

This works fine except for a client name of, for example, O'Donnell. When
the command button is clicked for O'Donnell I get the message "Syntax error
(missing operator) in query expression '[Lname] = 'O'Donnell".

The code for the command button is as follows:

Private Sub Command150_Click()
On Error GoTo Err_Command150_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FClient_and_sub_more"

stLinkCriteria = "[Lname]=" & "'" & Me![Lname] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command150_Click:
Exit Sub

Err_Command150_Click:
MsgBox Err.Description
Resume Exit_Command150_Click

I'm sure the problem is caused by the ' as part of the name .. any help
would be much appreciated for a newbie learning as I go along ... said that
before, but I'm still learning.

abay
 
T

tina

probably there is, but i don't know it. i can only suggest that 1) you
consider changing your primary key - unless you will never, ever, have two
clients with the same last name, or 2) if you're determined to stick with
the last name as primary key, watch this thread for a day or so. then if
nobody else posts a solution to the apostrophe problem, start a new thread
and include the information that your last name field is your table's
primary key (so you don't have to repeat our conversation again, with
somebody else). good luck.


Abay said:
Many thanks Tina for your reply ... actually the primary key is the last
name, so I guess the question is as stated by jouj .. is there away to
around the apostrophe ?

abay

tina said:
yes, that apostrophe is probably what's causing the error, but you would
probably be better off not using a last name field as your "link" between
the forms - for instance, what happens when you have two records with last
name "Smith"?

hopefully you have a primary key field, that is not a client name, in your
Client table. the primary key/foreign key is almost always the best
value
to
use in finding and retrieving a specific record.

hth


Abay said:
I have a "browse" tabular form which shows critical fields for clients
in
a
Client table, one line per client .. each line has a "command button" to
show "More" information .. which brings up a form containing all information
for a client .. the link between the forms is the Client name.

This works fine except for a client name of, for example, O'Donnell. When
the command button is clicked for O'Donnell I get the message "Syntax error
(missing operator) in query expression '[Lname] = 'O'Donnell".

The code for the command button is as follows:

Private Sub Command150_Click()
On Error GoTo Err_Command150_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FClient_and_sub_more"

stLinkCriteria = "[Lname]=" & "'" & Me![Lname] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command150_Click:
Exit Sub

Err_Command150_Click:
MsgBox Err.Description
Resume Exit_Command150_Click

I'm sure the problem is caused by the ' as part of the name .. any help
would be much appreciated for a newbie learning as I go along ... said that
before, but I'm still learning.

abay
 
A

Abay

Thanks again .. unfortunately the last name has to be the primary key ..will
do as you suggest ...

abay

tina said:
probably there is, but i don't know it. i can only suggest that 1) you
consider changing your primary key - unless you will never, ever, have two
clients with the same last name, or 2) if you're determined to stick with
the last name as primary key, watch this thread for a day or so. then if
nobody else posts a solution to the apostrophe problem, start a new thread
and include the information that your last name field is your table's
primary key (so you don't have to repeat our conversation again, with
somebody else). good luck.


Abay said:
Many thanks Tina for your reply ... actually the primary key is the last
name, so I guess the question is as stated by jouj .. is there away to
around the apostrophe ?

abay

tina said:
yes, that apostrophe is probably what's causing the error, but you would
probably be better off not using a last name field as your "link" between
the forms - for instance, what happens when you have two records with last
name "Smith"?

hopefully you have a primary key field, that is not a client name, in your
Client table. the primary key/foreign key is almost always the best
value
to
use in finding and retrieving a specific record.

hth


I have a "browse" tabular form which shows critical fields for
clients
in
a
Client table, one line per client .. each line has a "command
button"
to
show "More" information .. which brings up a form containing all
information
for a client .. the link between the forms is the Client name.

This works fine except for a client name of, for example, O'Donnell. When
the command button is clicked for O'Donnell I get the message "Syntax
error
(missing operator) in query expression '[Lname] = 'O'Donnell".

The code for the command button is as follows:

Private Sub Command150_Click()
On Error GoTo Err_Command150_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FClient_and_sub_more"

stLinkCriteria = "[Lname]=" & "'" & Me![Lname] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command150_Click:
Exit Sub

Err_Command150_Click:
MsgBox Err.Description
Resume Exit_Command150_Click

I'm sure the problem is caused by the ' as part of the name .. any help
would be much appreciated for a newbie learning as I go along ... said
that
before, but I'm still learning.

abay
 

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