Correct Syntax for appending form data to a Table

catbeasy

Registered User.
Local time
Today, 15:46
Joined
Feb 11, 2009
Messages
140
access 97..

Hi, I have a some code in a form that is supposed to append data from a subform into a table..

I'm getting an error on the line d.execute. The error is that I have too few parameters..

Here is what the sql evaluates to in the debug window..

"insert into tbl_req_tmp_A999999090211131727 (assoc_id) values (A999999)"

where the A999999 is the value of str_fld01 and assoc_id is the field in the table I want updated.

Did I mess up the syntax somewhere?

Thanks for any assistance..

The code is:

Dim d As Database
Dim str_sql As String
Dim str_fld01 As String
Dim str_fld02 As String
Set d = CurrentDb
str_fld01 = [frm_sub_mars_data].[Form]!txt_Assoc_ID
str_sql = "insert into tbl_req_tmp_A999999090211131727 (assoc_id) values (" & str_fld01 & ")"

d.Execute str_sql
d.Close
 
Because the field is text:

str_sql = "insert into tbl_req_tmp_A999999090211131727 (assoc_id) values ('" & str_fld01 & "')"

Note the extra single quotes around the value.
 
Because the field is text:

str_sql = "insert into tbl_req_tmp_A999999090211131727 (assoc_id) values ('" & str_fld01 & "')"

Note the extra single quotes around the value.

Perfect, thanks!
 

Users who are viewing this thread

Back
Top Bottom