Quotation marks in queries (1 Viewer)

B

brodie_ou

Guest
I have the following code in the Click Event of a button a form:

os.Open "select count(*) from [Tasks] where [SerialNumber] = '" & strTo & "' and " & _
"[Task No] = " & lngTaskNum & " and [TaskName] = '" & strTaskName & "' and [Type] = 'Insp'", CurrentProject.Connection

I am having problems if the variable strTaskName contains a single quote. I changed the query attempting to pass it with double quotes around the field value, but I assume I'll continue to run into problems if the variable contains double quotes.

I also attempted to edit the forms where this data is entered so the users cannot enter data that contains quote or double quotes, but have not successfully figured out the syntax of the validation rule.

Any ideas?
 

bjackson

Registered User.
Local time
Today, 18:39
Joined
Jan 3, 2003
Messages
404
try
"select count(*) from [Tasks] where [SerialNumber] =" & """" & strTo & """" & " and " & _
"[Task No] = " & lngTaskNum & " and [TaskName] = " & """" & strTaskName & """" & " and [Type] = " & """" & "Insp" & """" & ","

or you could declare a variable
Dim StrQuote As String

StrQuote = """"

"select count(*) from [Tasks] where [SerialNumber] =" & StrQuote & strTo & StrQuote & " and " & _
"[Task No] = " & lngTaskNum & " and [TaskName] = " & StrQuote & strTaskName & StrQuote & " and [Type] = " & StrQuote & "Insp" & StrQuote& ","
 

Users who are viewing this thread

Top Bottom