Executing an SQL Insert statement on a button click - Help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there, I have a screen that allows the user to enter in the values to go
into a table. When they click a button I want to execute an insert using the
values they entered. Should it look something like this?

Private Sub Save_Project_Click()

DoCmd.RunSQL = "INSERT INTO Project_Main (Project_Number, Is_Project,

Client_Code, Anecdotal_Name, Date_Created, Is_Active)" & _
"Values (" & Project_Number & ", " & Is_Project & ", " &
Client_Code & ", " & Anecdotal_Name & ", " & Date & ", " &
Is_Active & ")"

End Sub

This gives me an "Arguement not optional" Error (449). Can anyone please
tell me what I'm doing wrong here?

Thanks

Nick
 
I just changed my sql to:

DoCmd.RunSQL = "INSERT INTO Project_Main (Project_Number, Is_Project,
Client_Code, Anecdotal_Name, Date_Created, Is_Active)" & _
"Values (" & Project_Number & _
", " & Chr$(34) & Is_Project & Chr$(34) & _
", " & Chr$(34) & Client_Code & Chr$(34) & _
", " & Chr$(34) & Anecdotal_Name & Chr$(34) & _
", " & Chr$(34) & Date & Chr$(34) & _
", " & Chr$(34) & Is_Active & ");"

But I still get the arguement not optional error.
 
One problem that jumps out immediately is the missing space before the
keyword Values. Remember that this will be sent to Jet as one long string
of characters. You have:

...., Is_Active)Values (

If Date_Created is a Date type field, there is going to be a problem there
as well.

Change:
", " & Chr$(34) & Date & Chr$(34) & _
To:
", #" Date & "#" & _

HTH,
Randy
 
This will still have problems if you windows regional setting that show date
as "01.03.1998",so you can write like this
Change:
", " & Chr$(34) & Date & Chr$(34) & _
To:
", Date() ," & _



“Randy Harrisâ€ç¼–写:
 
Back
Top