Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi Everyone, I'm using the follo 1

Status
Not open for further replies.

Joey4Js

Technical User
Sep 5, 2002
9
0
0
AU
Hi Everyone,

I'm using the following code to loop through query records and add them to a table when my form opens:


Set rst = db.OpenRecordset("Companies For Job")

rst.MoveFirst

Do While rst.EOF = False

Set rstCompanies = db.OpenRecordset("tempIssueList", dbOpenDynaset)

rstCompanies.AddNew

rstCompanies("Company") = rst("Company Name")

rstCompanies.Update

rst.MoveNext

Loop


The problem I'm having is that my query criteria is linked to my form's Openargs (because I couldn't figure out how to set it using the VB module), and when my VB code is running there isn't any data in the query and it gives me the following error message: "Too few parameters. Expected: 1". Is it possible to set the query criteria to a numerical value using VBA?

Thanks,

Joe

 
Add something like this to the Forms Code

First the Form's RecordSource should be the Table [NewTable] with the Results of the Update.

Before Doing the Update Delete all the Records.

DoCmd.RunSQL "DELETE * FROM NewTable;"

Now Insert the New Records from the First Query

DoCmd.RunSQL "INSERT INTO NewTable ( ID, Category, Name )SELECT FromQueryName1.ID, FromQueryName1.Category, FromQueryName1.Name FROM FromQueryName1;"

And Again from the Next Query

DoCmd.RunSQL "INSERT INTO NewTable ( ID, Category, Name )SELECT FromQueryName2.ID, FromQueryName2.Category, FromQueryName2.Name FROM FromQueryName2;"


The above code should be executed before the Form is opened.

You could try to place the code in the "Form Load" Event. as this event happends before the records are displyed in your form.

Hope this helps

Pierre
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top