djblois
djblois

Reputation: 835

Invalid Operation trying to insert values in to Access Database

I have this code below and when I try to run it, it crashes with the error message, "Invalid Operation" on the last line in the code. All the Syntax looks correct. What am I doing wrong?

PCycle = PreviousCycle(CurrentCycle(Me.cobMainType.Value), mainType(Me.cobMainType.Value))

SQL = "INSERT INTO tblVehMainType (MainID, PartID, VehTypeID)"
SQL = SQL & " Select " & Me.cobMainType & ", PartID, VehTypeID"
SQL = SQL & " From tblVehMainType "
SQL = SQL & " WHERE vehTypeID = " & Me.cobVehType & " AND MainID = " & PCycle & ";"

Set rst = CurrentDb.OpenRecordset(SQL)

Upvotes: 1

Views: 549

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123829

An INSERT statement does not return a recordset so you should not use .OpenRecordset to run it. You should use .Execute instead.

Upvotes: 2

Related Questions