If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Syntax error
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 |
#2
|
|||
|
|||
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" wrote in message ... 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 |
#3
|
|||
|
|||
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" wrote: 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" wrote in message ... 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 |
#4
|
|||
|
|||
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" wrote in message ... 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" wrote in message ... 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 |
#5
|
|||
|
|||
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" wrote in message ... 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" wrote in message ... 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" wrote in message ... 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 |
#6
|
|||
|
|||
Thanks again .. unfortunately the last name has to be the primary key ..will
do as you suggest ... abay "tina" wrote in message ... 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" wrote in message ... 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" wrote in message ... 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" wrote in message ... 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 |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Command Line Option Syntax Error | Roy | Powerpoint | 2 | February 24th, 2005 05:27 PM |
SQL Syntax Error | Wantula | Database Design | 3 | November 9th, 2004 02:01 AM |
Still Getting SQL Syntax Error | Wantula | Database Design | 1 | November 5th, 2004 02:34 PM |
(!Syntax Error, *) | Suse | Mailmerge | 2 | September 24th, 2004 09:58 AM |
Question on lauching access and syntax error during batch file | Adam Raff | General Discussion | 2 | August 12th, 2004 04:20 AM |