Append records to table from a Form

G

Guest

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
 
G

Guest

For dates, use the # character rather than single quotes as in

VALUES ('" & txtUserName & "', #" & txtDate & "#);"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top