Skip to content
Advertisement

Problem regarding For Loop using SQL in Access VBA

I am working on a employee DB in which there is a training form. I have over 2000 employees who need trainings from time to time. I need to create batches of predetermined number (i.e. 50) of employees in that form. Also, I need to create them for each new training. So trainings are linked to TrainingID. I have created a for loop statement just as the following:

(Note: TBatchtxt is the total batches need to be created)

But when I run it a pop up appears saying StartC.

Also I want the result to like the following:

BatchNo TrnID

1 101

2 101

3 101

Please HELP. Thanks.

Advertisement

Answer

The SQL statement that you are executing doesn’t “know” what values you are trying to insert – you must concatenate the values into the SQL string. As a tip for debugging, you could place a Debug.Print StrSQL on the line after you have concatenated the values in to see what it actually is.

Also, the SQL statement is not inside the loop, so the values will never change. Conversely, there is no need to change SetWarnings inside the loop – you can just change it outside the loop.

Regards,

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement