Append records to table from a Form

  • Thread starter Thread starter Jologs
  • Start date Start date
J

Jologs

Hi:

I created a tblLog to tract the users which has "Username"(captured
NetID) and "Date"(=now).

I created a frmSwitchboard bounds to tblLog and add the "txtUsername"
and "txtDate". I got an error using the codes below "Syntax error in
INSERT INTO statement". I'm a beginner and don't know how to properly
execute a query. Thanks.

Private Sub Form_Close()

Dim stDocName As String
Dim strSQL As String

strSQL = "INSERT INTO tblLog (Username,Date) VALUES ('" &
txtUserName & "', '" & txtDate & "');"
stDocName = "Switchboard"

If Me.txtCountUserName.Value = 0 Then
DoCmd.OpenForm "frmUnauthorizedUser"
Else
CurrentDb.Execute strSQL
DoCmd.OpenForm stDocName
End If

End Sub
 
The date needs # signs around it, not quotes.
Try using Date() and not Now().
Date is a reserved word, I wouldn't use it as a field name.

strSQL = "INSERT INTO tblLog (Log_Username, Log_Date) VALUES ('" &
txtUserName & "', #" & txtDate & "#);"

Ron
 
Back
Top