Correct Syntax

D

DS

Is this correct?

CurrentDb.Execute "INSERT Into
tblChecksTMP(CheckID,ChkCustomerID,ChkServer,ChkTabID,ChkGuests, " & _
"ChkTypeID,ChkSepCheck,ChkDividedCheck,ChkDivideBy,ChkOldCheckID) IN '" &
REDACT() & "' " & _
"VALUES(" & Forms!frmPadDivider!TxtDPNewSalesID & ",1," &
Forms!frmPadDivider!TxtDPServer & ", " & _
"" & Forms!frmPadDivider!TxtDPTableNumber & "," & 1 & "," & 1 & "," & 0 & ",
" & _
"" & -1 & "," & Forms!frmPadDivider!TxtDivideCheck & ", " & _
"" & Forms!frmPadDivider!TxtDPOldSalesID & ")"

Or is this the correct way?

CurrentDb.Execute "INSERT Into tblChecksTMP IN '" & REDACT() &
"'(CheckID,ChkCustomerID,ChkServer,ChkTabID,ChkGuests, " & _
"ChkTypeID,ChkSepCheck,ChkDividedCheck,ChkDivideBy,ChkOldCheckID) " & _
"VALUES(" & Forms!frmPadDivider!TxtDPNewSalesID & ",1," &
Forms!frmPadDivider!TxtDPServer & ", " & _
"" & Forms!frmPadDivider!TxtDPTableNumber & "," & 1 & "," & 1 & "," & 0 & ",
" & _
"" & -1 & "," & Forms!frmPadDivider!TxtDivideCheck & ", " & _
"" & Forms!frmPadDivider!TxtDPOldSalesID & ")"

IN '" & REDACT() & "' points to the external database path
Thanks
DS
 
D

Douglas J. Steele

Neither.

The numeric constants should be inside the quotes:

CurrentDb.Execute "INSERT Into tblChecksTMP IN '" & REDACT() &
"'(CheckID,ChkCustomerID,ChkServer,ChkTabID,ChkGuests, " & _
"ChkTypeID,ChkSepCheck,ChkDividedCheck,ChkDivideBy,ChkOldCheckID) " & _
"VALUES(" & Forms!frmPadDivider!TxtDPNewSalesID & ",1," &
Forms!frmPadDivider!TxtDPServer & ", " & _
Forms!frmPadDivider!TxtDPTableNumber & ", 1 , 1 , 0 , " & _
" -1 & ," & Forms!frmPadDivider!TxtDivideCheck & ", " & _
Forms!frmPadDivider!TxtDPOldSalesID & ")"

Note that there's no reason for the "" you had.

For what it's worth, I prefer not using the IN keyword. Rather than

INSERT INTO Table1 IN 'E:\Folder\File.mdb'

I use

INSERT INTO [;Database=E:\Folder\File.mdb].Table1

No real reason (other than it eliminates needing to worry about where the IN
goes!)
 
D

DS

Great Thanks...Always informative. I appreciate the extra information.
Sincerely,
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

More Correct Syntax 5
For Loop 6
DSum Problem 2
Loop and Insert Problem 5
SQL and Null 10
Correct Syntax 4
INSERT Syntax Problem 2
Loop Question 2

Top