Aya Abdelsalam
Aya Abdelsalam

Reputation: 500

INSERT statement in SQl

I am trying to save record in more then one table i am using insert statement but it gives me "syntax error in the INSERT INTO statement" Here is my code

strSQL = " INSERT INTO [2011 Nurse Patient Index]
                (File Number, Patient name ,Gender , AgeRTU , Nationality , 
                 Diagnosis , Other , Appointment , Date)
         VALUES('" & File_NumberRTU.Value & "','" & Patient_nameRTU.Value & "' , 
                '" & GenderRTU.Value & "', '" & AgeRTU.Value & "' , 
                '" & NationalityRTU.Value & "' , '" & DiagnosisRTU.Value & "' ,
                '" & OtherRTU.Value & "' , '" & AppointmentRTU.Value & "' ,
                '" & DateRTU.Value & "')"
        CurrentDb.Execute strSQL

the error appears in this line

CurrentDb.Execute strSQL

Can anyone tell me where I went wrong? Thank you

Upvotes: 0

Views: 4097

Answers (2)

Logan Serman
Logan Serman

Reputation: 29870

If the Date column is of type Date or Datetime in your database, you may have to surround DateRTU.Value with #'s, i.e.,

INSERT INTO 
    [2011 Nurse Patient Index]([File Number], [Patient name], Gender, AgeRTU, Nationality, Diagnosis, Other, Appointment, Date) 
VALUES 
    ('" & File_NumberRTU.Value & "', 
     '" & Patient_nameRTU.Value & "', 
     '" & GenderRTU.Value & "', 
     '" & AgeRTU.Value & "', 
     '" & NationalityRTU.Value & "', 
     '" & DiagnosisRTU.Value & "', 
     '" & OtherRTU.Value & "', 
     '" & AppointmentRTU.Value & "', 
     '#" & DateRTU.Value & "#')"

Upvotes: 3

Joe Stefanelli
Joe Stefanelli

Reputation: 135808

Try square brackets around [File Number] and [Patient name].

strSQL = " INSERT INTO [2011 Nurse Patient Index]([File Number], [Patient name] ,Gender , AgeRTU , Nationality , Diagnosis , Other , Appointment , Date)VALUES('" & File_NumberRTU.Value & "','" & Patient_nameRTU.Value & "' , '" & GenderRTU.Value & "', '" & AgeRTU.Value & "' , '" & NationalityRTU.Value & "' , '" & DiagnosisRTU.Value & "' , '" & OtherRTU.Value & "' , '" & AppointmentRTU.Value & "' , '" & DateRTU.Value & "')"
    CurrentDb.Execute strSQL

Upvotes: 1

Related Questions