Hello,
I am using Access 2003.
Is it possible to use string variables in the INSERT INTO statement?
I am using the INSERT INTO statement to add a long list of contacts to
a group by looping through the recordset (based on a linked
spreadsheet, 'tbl_group_impo rt') and using the INSERT INTO statement
on each loop. I am using the rst.Fields.Item ("FieldName" ) method to
assign a value to the string variables. However, when I run the code,
it prompts me for the variable values.
I am executing the SQL using DoCmd.RunSQL.
I would really appreciate any assistance.
Thanks,
Franc.
Here is the code;
Dim contact As Recordset
Dim title As String
Dim first_name As String
Dim insert_sql As String
Dim group_id As Integer
group_id = Forms![frm_group_view]![group_id]
Set contact = CurrentDb.OpenR ecordset("tbl_g roup_import")
contact.MoveFir st
Do Until contact.EOF
title = contact.Fields. Item("contact_t itle")
first_name = contact.Fields. Item("contact_f irst_name")
insert_sql = "INSERT INTO
qry_group_membe r(group_member_ group_id,contac t_title,contact _first_name)"
& _
"VALUES (group_id,title ,first_name)"
DoCmd.RunSQL insert_sql
contact.MoveNex t
Loop
I am using Access 2003.
Is it possible to use string variables in the INSERT INTO statement?
I am using the INSERT INTO statement to add a long list of contacts to
a group by looping through the recordset (based on a linked
spreadsheet, 'tbl_group_impo rt') and using the INSERT INTO statement
on each loop. I am using the rst.Fields.Item ("FieldName" ) method to
assign a value to the string variables. However, when I run the code,
it prompts me for the variable values.
I am executing the SQL using DoCmd.RunSQL.
I would really appreciate any assistance.
Thanks,
Franc.
Here is the code;
Dim contact As Recordset
Dim title As String
Dim first_name As String
Dim insert_sql As String
Dim group_id As Integer
group_id = Forms![frm_group_view]![group_id]
Set contact = CurrentDb.OpenR ecordset("tbl_g roup_import")
contact.MoveFir st
Do Until contact.EOF
title = contact.Fields. Item("contact_t itle")
first_name = contact.Fields. Item("contact_f irst_name")
insert_sql = "INSERT INTO
qry_group_membe r(group_member_ group_id,contac t_title,contact _first_name)"
& _
"VALUES (group_id,title ,first_name)"
DoCmd.RunSQL insert_sql
contact.MoveNex t
Loop
Comment