Copy form data into table

scuddersm

Registered User.
Local time
Today, 09:21
Joined
Mar 9, 2011
Messages
31
Good morning all.

I'm trying to copy information from a unbound txt box on a form into my table and I am having trouble with the formatting:

table name: tblNewJoinDate
Field Name: Last Run

Form txtbox name: New Join Date

I'm getting a SQL INSERT INTO formatting error message
Code:
 Private Sub New_Join_Date_Change()
Dim SQL As String
  
 SQL = "INSERT INTO tblNewJoinDate (Last Run) VALUES (" & Me.New_Join_Date.Value & ");"
  
 DoCmd.RunSQL SQL
  
 End Sub

Thanks for any help.

Scott
 
Date values require "#" delimiters when expressed as literal values in SQL. Try...
Code:
SQL = "INSERT INTO tblNewJoinDate ( LastRun ) VALUES ( #" & Me.NewJoinDate & "# );"
It's also good practice to never name anything with an embedded space, so do "LastRun" or "NewJoinDate." You got it right with your "tblNewJoinDate"
 
Thanks for the help. It worked with the following:
Code:
 Dim SQL As String
 SQL = "INSERT INTO tblNewJoinDate ( LastRun ) VALUES ( #" & Me.NewJoinDate.Value & "# );"
 DoCmd.SetWarnings False
DoCmd.RunSQL SQL
DoCmd.SetWarnings True
 
If you use the DAO.Database.Execute method you don't have to SetWarnings off and on, and you could do . . .
Code:
   Dim SQL As String
   SQL = "INSERT INTO tblNewJoinDate ( LastRun ) VALUES ( #" & Me.NewJoinDate.Value & "# );"
   CurrentDb.Execute SQL, dbFailOnError
 

Users who are viewing this thread

Back
Top Bottom