Correct Syntax

  • Thread starter Thread starter DS
  • Start date Start date
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
 
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!)
 
Back
Top