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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeat append query programmatically

Status
Not open for further replies.

topdesk123

Programmer
Sep 27, 2001
76
US
Hello!

Is there a way to run an append query the number of times based on a number entered in a form?

Please let me know if I need to provide additional information.

Thanks in advance!
topdesk123
 
In the VBA help file take a look at the For ... Next instruction.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

Thank you for the advice. I have:

Dim I As Integer
For I = Me![#ofWS] To Me![#ofWS] + 1
DoCmd.OpenQuery "add WS"
Next I

Running from a command button (that performs other operations as well). When I tested it the first time, I entered 3 in me![#ofws] - it worked fine. BUT, I changed it to 1 now, and it's still running the query 3 times. What did I miss?

THANK YOU!!
 
Thank you traingamer - now the query is just running random numbers of times. I enter 1 - it runs 3, 6, 4 times. I enter 3, it runs 8 times, etc....

I have:
Dim I As Integer
For I = 1 To Me![#ofWS]
DoCmd.OpenQuery "add WS"
Next I

Thanks again!
 
I got this to work (although I have no idea why!)

Dim I As Integer
For I = 1 To Me![#ofWS] - 1
DoCmd.OpenQuery "add WS"
Next I

Thank you again for your help!
 
My dumb mistake - I still had the append query running one more time after the for....next statement.

So, this works as it is supposed to:

Dim I As Integer
For I = 1 To Me![#ofWS]
DoCmd.OpenQuery "add WS"
Next I

THANKS!!
topdesk123


 
That doesn't compute...

Try setting a break point within the loop and seeing what it's doing.

Does "add WS" add one and only one row when run by itself?

traingamer
 
excellent - forget my prior comment as it apparently was posted after yours instead of before...

traingamer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top