syntax

  • Thread starter Thread starter Miranda
  • Start date Start date
M

Miranda

hi,

could someone please help me out with the following statement

Dim db As DAO.Database
Dim strSql As String

Set db = CurrentDb()
strSql = "INSERT INTO labourLog (sheetNumber, labourType, jobDesc, hours,
date, empID, empName)" & _
" VALUES (" & Me.sheet & ", '" & Me.labourType & "' , '" & Me.Text80 & "' ,
" & Me.hours & " , " & Me.currentDate & " , '" & Me.emp.Value & "', '" &
Me.emp.Column(0) & "' );"

db.Execute strSql, dbFailOnError


Set db = Nothing


me.sheet is a number
me.labourType is a string
me.text80 is a string
me.hours is a number
me.currentDate is date
me.emp.value is a string
me.emp.column(0) is a string

if i do ?strsql this is the output i get
INSERT INTO labourLog (sheetNumber, labourType, jobDesc, hours, date, empID,
empName) VALUES (123, 'minerOT' , 'Mega Bolts',3 , 30/01/2004 , 'matt1',
'Bourke, Miranda' );


but i get an error on

db.Execute strSql, dbFailOnError

any ideas?!?!

thanks a lot
 
Miranda,

Since 'date' is a reserved word, and generally shouldn't be used as a
field name, it is prudent at least to enclode it in []s in your INSERT
INTO clause. And the CurrentDate needs the date qualifiers ## around
it. So, try this...
strSql = "INSERT INTO labourLog (sheetNumber, labourType, jobDesc,
hours, [date], empID, empName)" & _
" VALUES (" & Me.sheet & ", '" & Me.labourType & "', '" & Me.Text80 &
"', " & Me.hours & ", #" & Me.currentDate & "#, '" & Me.emp.Value & "',
'" & Me.emp.Column(0) & "' );"
 
(already answered in the "forms" newsgroup).

Please do not multi-post, i.e. sending multi posts on the same question to
different newsgroup. If you think it is necessary for your question to
appear in more than one newsgroup (it rarely necessary, though), use
cross-posting, i.e. sending ONE post with up to 3 relevant newsgroup
addresses on the one post.
 
Back
Top