Question Please help Insert SQL code fault

brittaink

Registered User.
Local time
Today, 23:03
Joined
Dec 13, 2006
Messages
46
Hi,
Could someone please tell me what may be wrong with this code:

DoCmd.RunSQL "Insert Into tblChecks (_CheckType, Comment, _Checker, Date, Time)" & _
"Values ('" & Me.CheckType.Value & "','" & Me.Comment.Value & "','" & Me.Checker.Value & "','" & Me.Date.Value & "','" & Me.Time.Value & "')"

The table column names are right although there is also a id coulumn which is an autonumber. The me."value" are all correct but still no joy.

Any idea's would be greatly appreciated

Keith Brittain
 
If you are using ME.fieldname then you must be running the code from the form modules and the form must be open.

What is the error message you are actually getting.

You don't actually need to put Me.CheckType.Value. Me.CheckType should work just as well.

I assume that CheckType,Comment etc are the name of fields on your form. This syntax needs the form field names in order to work.

It could be worth using Me!CheckType
 
I note that you have a date field and a time field.

The dates need a # delimiter not a ' when joining strings. I'm not sure about time, would this be a # as well? Not sure as never required to store times before. Would be interested to know of course.

Code:
DoCmd.RunSQL "Insert Into tblChecks (_CheckType, Comment, _Checker, Date, Time)" & _
"Values ('" & Me.CheckType.Value & "','" & Me.Comment.Value & "','" & Me.Checker.Value & "',#" & Me.Date.Value & "#,#" & Me.Time.Value & "#)"
 

Users who are viewing this thread

Back
Top Bottom