bob said:
Thanks Dirk..
My error appears when I use the insert statement..it says
it is not right Syntax.
That's not the exact error message. Next time, please post the exact
error message. It matters, in tracking down bugs.
If I use your code and have 4 text values in
progcode,coursenum,studentclocknum and exempt....Exempt is
a checkbox..is that text or numeric?
How would the code you have me change then?
I don't understand; how is Exempt *both* a "text value" and a check
box? Normally, a check box is bound to a yes/no (also called "boolean")
field in the table. The significant issue here is the field type as
established in the table design. Bear in mind also that, technically,
what you have in your table are *fields*, while what you have on your
form are *controls* (which may be bound to fields). Sometimes that's an
important distinction, sometimes not.
Assuming that the fields ProgramCode, CourseNum, and StudentClockNum are
all defined as text fields in tblAttendance, and Exempt is a yes/no
field, the code might look like this:
'---- start of code ----
Private Sub Command46_Click()
Dim rs As DAO.Recordset
Dim db As DAO.Database ' for insert queries
Dim strSQL As String
Set db = CurrentDb
Set rs = Me.RecordsetClone
With rs
If .RecordCount <> 0 Then .MoveFirst
Do Until .EOF
strSQL = _
"INSERT INTO tblAttendance " & _
"(StudentClockNum, ProgramCode, CourseNum, " & _
"LoginTime, Exempt, SHours) " & _
"VALUES (" & _
"'" & !studentclocknumber & "', " & _
"'" & !progcode & "', " & _
"'" & !cnum & "', " & _
Format(!login, "\#mm/dd/yyyy hh:nn:ss\#") & ", " & _
!exemptall & ", " & _
!thours & ")"
' Uncomment if needed for debugging:
'debug.print strSQL
db.Execute strSQL, dbFailOnError
.MoveNext
Loop
End With
Set rs = Nothing
Set db = Nothing
End Sub
'---- end of code ----
Do you see how I've inserted single-quotes (') around the values for the
text fields? I also changed it around slightly to make it easier to
debug, in case this version also gets an error. If it does,
"un-comment" the line "debug.print strSQL", then run it again and press
Ctrl+G to see in the Immediate Window exactly what SQL we attempted to
execute. If necessary, copy and paste that into a reply message.