SQL INSERT -- asking for parameters when executing?!

mbrost

Registered User.
Local time
Yesterday, 22:24
Joined
Jun 27, 2005
Messages
26
Hi all,

I've searched for a solution, and the proposed solution didn't work for me.

I am executing an SQL statement to insert values into a History table when deleting a value in a subform. Two of the 5 values are asking me for parameters when the SQL executes and I cant figure out why! The datatypes they are inserting into are correct and I'm at a loss. The 2 values giving me grief are Manufacturer and Model.

Here's the code:

Dim sSQLMachHistory As String

MsgBox "me.acctid: " & Me.AccountID
MsgBox "me.manufac: " & Me.Manufacturer & " me.serial: " & Me.SerialNumber
MsgBox "model: " & Me.Model

'Insert into History Table:
sSQLMachHistory = "INSERT INTO tblMachineHistory (SerialNumber, Manufacturer, Model, AccountID, MachineID) VALUES (" & Me.SerialNumber & ", " & Me.Manufacturer & ", " & Me.Model & ", " & Me.AccountID & ", " & Me.MachineID & ")"

MsgBox sSQLMachHistory

DoCmd.SetWarnings False
DoCmd.RunSQL sSQLMachHistory
DoCmd.SetWarnings True

My message boxes show me all the values are displaying and should be inserting into the table -- any ideas??? :confused:

cheers

Mike
 
FIXED :)

You need to put "" around the text field values to act as a regular double quote -- I was thrown for a loop since my serial number is a text field, but this value was all numbers.

Well, maybe this will help any other newbies like me ;)
 
Mike,

Punctuation. You need to delimit the strings with a single-quote. Dates
use "#", numbers need nothing.

Code:
sSQLMachHistory = "INSERT INTO tblMachineHistory (SerialNumber, " & _
                  "       Manufacturer, Model, AccountID, MachineID) " & _
                  "VALUES (" & Me.SerialNumber & ", '" & Me.Manufacturer & "', '" & _
                               Me.Model & "', " & Me.AccountID & ", " & _
                               Me.MachineID & ")"

Wayne
 

Users who are viewing this thread

Back
Top Bottom