![]() |
|
||||||||
| Site Links |
| Consulting |
| Knowledge Base |
| Training |
| Forum |
| Articles |
| Resources |
| Products |
| Cool Tools |
| Contact |
| About Us |
| Go to Page... |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
|
Solved: Loop to create repeating SQL statment with incrementing variables
I have a list of ID numbers in an excel sheet and those numbers will be the fields in the SQL SELECT statment like this:
SELECT [IDnumber1] from mytable where Field=[Variable] and Field1=[Variable1] I'm trying to get VBA to run the SELECT statement, write the results to Excel then Run it again and move to the next variable in the list so the second time thru would be: SELECT [IDnumber2] from mytable where Field=[Variable] and Field2=[Variable2] Keep going until it goes all the way through the list of numbers. Some of the variables in the Select dont change and others do. The length of the list varies so I planning to have a COUNTA return the total items in the list then use that result to form a For i = 1 to [COUNTA result] All this is due to a poor database design and the use of many VBA reserved words in the database fields. (Not my design!) Here is what I have so far..I put several breaks in the SQL statment so the variables would be on a new line by themselves.. VBA:
VBA tags courtesy of www.thecodenet.com
|
|
Local Time: 06:52 PM
Local Date: 05-18-2013 |
|
|
|
#2 |
|
|
Couldnt figure out how to edit my post...
Still working on this...I think it needs to be done witha nested loop, the outer loop builds the sql statment while the inner loop updates the variables in the sql statment. I updated the code by breaking the SQL statment into several pieces so that the strings containing the variables can be separated and updated. VBA:
VBA tags courtesy of www.thecodenet.com
|
|
Local Time: 06:52 PM
Local Date: 05-18-2013 |
|
![]() |
| Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|


