By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,401 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,401 IT Pros & Developers. It's quick & easy.

Cannot Get Code Right To Insert From Form

intelligen
P: 2
Hi All,

I have been struggling with this for two days now...........

I have variables made up to test data for all values to go in to a table (TAuditLog) which is an all Text fields table. All of the variables are verified OK via MsgBox (and appear correctly as they will / should go into the table.)

I keep getting the error 3134 (which refers me to the DoCmd line) but that is the only indicator I get.

I think it is a simple syntax error but have searched for examples here and on the web, and this code is the closest yet.

Note: the variables not hard coded here come from captions in the form.

Dim SQL As String

TempEmpName = "BLOGGS"
TransactionKeyText = DateText.Caption & TimeStartedText.Caption
StandardText = "Still Running"

SQL1 = "INSERT INTO TAuditLog ([strEmpName], [strDepartment], [strTransactionKey], [strDate], [strTimeStart], [strTimeStop], [strDuration)]"
SQL2 = " VALUES ('" & TempEmpName & "', '" & DepartmentText.Caption & "', '" & TransactionKeyText & "', "
SQL3 = "'" & DateText.Caption & "', '" & TimeStartedText.Caption & "', '" & StandardText & "', '" & StandardText & "')"

SQLDo = SQL1 & SQL2 & SQL3
'Confirm string before insert to table
MsgBox SQLDo

DoCmd.RunSQL SQLDo

Any help gratefully appreciated. This is driving me nuts!!

Thanks,
John B
Oct 7 '06 #1
Share this Question
Share on Google+
1 Reply


PEB
Expert 100+
P: 1,418
PEB
Hi John,

There is really a fault:
change this line to:

SQL1 = "INSERT INTO TAuditLog ([strEmpName], [strDepartment], [strTransactionKey], [strDate], [strTimeStart], [strTimeStop], [strDuration])"

And:


SQL3 = "'" & DateText.Caption & "', '" & TimeStartedText.Caption & "', '" & StandardText & "', '" & StandardText & "');"

:)

Hi All,

I have been struggling with this for two days now...........

I have variables made up to test data for all values to go in to a table (TAuditLog) which is an all Text fields table. All of the variables are verified OK via MsgBox (and appear correctly as they will / should go into the table.)

I keep getting the error 3134 (which refers me to the DoCmd line) but that is the only indicator I get.

I think it is a simple syntax error but have searched for examples here and on the web, and this code is the closest yet.

Note: the variables not hard coded here come from captions in the form.

Dim SQL As String

TempEmpName = "BLOGGS"
TransactionKeyText = DateText.Caption & TimeStartedText.Caption
StandardText = "Still Running"

SQL1 = "INSERT INTO TAuditLog ([strEmpName], [strDepartment], [strTransactionKey], [strDate], [strTimeStart], [strTimeStop], [strDuration)]"
SQL2 = " VALUES ('" & TempEmpName & "', '" & DepartmentText.Caption & "', '" & TransactionKeyText & "', "
SQL3 = "'" & DateText.Caption & "', '" & TimeStartedText.Caption & "', '" & StandardText & "', '" & StandardText & "')"

SQLDo = SQL1 & SQL2 & SQL3
'Confirm string before insert to table
MsgBox SQLDo

DoCmd.RunSQL SQLDo

Any help gratefully appreciated. This is driving me nuts!!

Thanks,
John B
Oct 8 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.