Copy form data into table (1 Viewer)

scuddersm

Registered User.
Local time
Today, 06:49
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
 

MarkK

bit cruncher
Local time
Today, 03:49
Joined
Mar 17, 2004
Messages
8,186
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"
 

scuddersm

Registered User.
Local time
Today, 06:49
Joined
Mar 9, 2011
Messages
31
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
 

MarkK

bit cruncher
Local time
Today, 03:49
Joined
Mar 17, 2004
Messages
8,186
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

Top Bottom