PC Review


Reply
Thread Tools Rate Thread

Converting RUNSQL Macro to VBA

 
 
Michael Carakatsane
Guest
Posts: n/a
 
      26th Sep 2003
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

 
Reply With Quote
 
 
 
 
Wendy
Guest
Posts: n/a
 
      26th Sep 2003
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
>
>.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RunSQL within a Macro Dave Reardon Microsoft Access 1 16th Sep 2008 12:20 PM
Macro RUNSQL vs Queries Geoff Microsoft Access Queries 1 28th Aug 2007 10:48 PM
converting Lotus 123 macro to Excell macro =?Utf-8?B?bWFyayBo?= Microsoft Excel Misc 6 11th Jul 2005 01:28 PM
Macro - RunSQL =?Utf-8?B?R1c=?= Microsoft Access Macros 3 2nd Nov 2004 05:40 PM
Macro RunSQL Statement Message Suppression =?Utf-8?B?QmFycnkgRGF2aWRzb24=?= Microsoft Access 3 30th Dec 2003 03:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 AM.