creating parameter query via DAO

penfold1992

Registered User.
Local time
Today, 23:06
Joined
Nov 22, 2012
Messages
169
Hi, first off, i dont know much about SQL so I wont be able to help that much however...

I have a simple command

Code:
If (IsNull(strRequester.Value) = False) And (strRequester <> "") Then
    strRequester2 = strRequester.Value
Else
If InsertFlag <> False Then
    MsgBox ("Requester details can not be blank.")
    InsertFlag = False
End If
End If

so this says "If something is in the box, record it as a text) however there are errors when you add the symbol " ' " to the fields, they start to cause errors.

ive had a look at the answer that is... "Parameter queries" or "Parameter Queries" however I am not sure how to use them properly.

another issue is that I am using DAO as my database which I think is causing the problem.

could someone tell me how I should be using them to replace the simple method I was using before? I am using DAO 3.6
 
penfold1992, your question does not make much sense to me.. For starters, the code you provided has nothing to do with DAO.. Why you are looking for Parametrized DAO queries..

The error you are getting could be tacked by using either Chr(34) or """"
 
Apologies for not making it clear.

I am using this command to enter data: (ive stripped it back a bit so its smaller, i dont need to show all of it anyway)

Code:
CurrentDb.Execute "INSERT INTO [Initial Request] VALUES ( " + strType + "','" + strRequester2 + "','" + strTime + "')"

and the variables are obtained like such:
If (IsNull(strRequester.Value) = False) And (strRequester <> "") Then strRequester2 = strRequester.ValueElseIf InsertFlag <> False Then MsgBox ("Requester details can not be blank.") InsertFlag = FalseEnd IfEnd If
however when somebodies name is... O'neal for example, the apostraphy is causing an error because of the way the SQL works. So I need a way of being able to capture the data as text without causing the error to occur.

After browsing the internet the answer apparently is "Parameter Queries".

I know that this method of inserting data into a database is not very good (I wasnt the initial coder) but im sure there is a workaround to allowing special characters to be entered into the database without causing an error
 

Users who are viewing this thread

Back
Top Bottom