INSERT INTO problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code:

INSERT INTO [Table1] ([First Name], MI, [Last Name])
SELECT [Table1].[First Name], [Table1].MI, [Table1].[Last Name]
FROM [Table1]
WHERE [Table1].[ID] = [Forms]![Master_frm]![ID]

I keep getting the run time error 3061, stating "Too few parameters.
Expected 1." Does anyone have any insight or explanation?
 
How are you attempting to use that SQL?

If it's from within VBA, presumably you're putting the SQL statement into a
string and attempting to run the string. You need to pass the value of the
control to the string, rather than simply referring to the control in the
string:

strSQL = "INSERT INTO [Table1] ([First Name], MI, [Last Name]) " & _
"SELECT [Table1].[First Name], [Table1].MI, [Table1].[Last Name] " & _
"FROM [Table1] " & _
"WHERE [Table1].[ID] = " & [Forms]![Master_frm]![ID]

CurrentDb.Execute strSQL, dbFailOnError

This assumes that Table1.ID is a numeric field. If it's text, the last line
should be

"WHERE [Table1].[ID] = " & Chr$(34) & [Forms]![Master_frm]![ID] & Chr$(34)
 
Back
Top