If I understand what you are trying to do, here's a
possible solution:
docmd.runsql "insert into ..." etc.
if you don't set warning messages off first, this will
work exactly the same as if you were opening the SQL
statement saved as an action query from the database
window.
I hope this helps...
--Wendy
>-----Original Message-----
>I want to convert a Macro I use to the equivalent VBA
code.
> The Macro is a RUNSQL. I copied the SQL code from the
>Macro and put it into a Query Definition that I execute
as
>an action. The code is:
>
>
>Private Sub cmdAdd_to_Summary_Click()
>Dim qdf As QueryDef
>Dim StrSQL As String
>StrSQL = "Insert INTO Summary(Contact_Id) Select
>List_Sel_Records.Contact_Id from List_Sel_Records"
>Set qdf = CurrentDb.CreateQueryDef("", StrSQL)
>qdf.Execute dbFailOnError
>qdf.Close
>End Sub
>
>When I execute the VBA code after sucessfully running it
>once and the records I am inserting into table Summary
are
>short, I get a Run-Time Error 3061 Too few parameters.
>Expected 1. If it?s the first time through and I select
>all records in underlying table with the query
>List_Sel_Records it inserts the records perfectly.
>
>What I would like is for the VBA code to execute like the
>Macro. When the code runs I would like the alert message
>to be displayed which says I am going to append so many
>records. If there are duplicate keys, it would then give
>me another warning message to which I respond Yes and the
>table is updated with just the new unique keys.
>
>Is there a way to get the equivalent action in VBA.
>
>Thanks.
>
>Michael
>
>.
>
|