B
Baby Face Lee
Hello (again)
Sorry to keep bothering you guys but I'm having probs trying to do a loop.
I've got a control (well two infact) that each have the same name except for
a number at the end (eg cboEstCode1 to cboEstCode12) - there are 12 of them.
I'm running some SQL to insert the value in each control into a table. I
thought I'd do a For/Next loop that goes round 12 times adding the digit to
the end of the control name but the SQL is taking the string values literally
(not surprisingly) rather than finding the value that's in the name of the
control.
Here's my code:
Set db = DBEngine(0)(0)
For intEstCode = 1 To 12
stEstCode = "cboEstCode" & intEstCode
For intCands = 1 To 12
stCands = "txtCands" & intCands
strSQL = "INSERT INTO tbl_Estimates (CentreNo, EstCode, Cands)" _
& " VALUES (" & Me!cboCentreNo & ", " & "'" & stEstCode & "'" & ", "
& stCands & ");"
db.Execute strSQL
Exit For
Next
Next
I know this is not the way a form should be constructed but I'm trying to
'push' the data into a table to improve speed and a continuous form doesn't
work because being Unbound it doesn't hold more than one record at a time.
Sorry for all the waffle but can you help with this? Have I got the loop
structure right too?
Thanks guys!
Lee
Sorry to keep bothering you guys but I'm having probs trying to do a loop.
I've got a control (well two infact) that each have the same name except for
a number at the end (eg cboEstCode1 to cboEstCode12) - there are 12 of them.
I'm running some SQL to insert the value in each control into a table. I
thought I'd do a For/Next loop that goes round 12 times adding the digit to
the end of the control name but the SQL is taking the string values literally
(not surprisingly) rather than finding the value that's in the name of the
control.
Here's my code:
Set db = DBEngine(0)(0)
For intEstCode = 1 To 12
stEstCode = "cboEstCode" & intEstCode
For intCands = 1 To 12
stCands = "txtCands" & intCands
strSQL = "INSERT INTO tbl_Estimates (CentreNo, EstCode, Cands)" _
& " VALUES (" & Me!cboCentreNo & ", " & "'" & stEstCode & "'" & ", "
& stCands & ");"
db.Execute strSQL
Exit For
Next
Next
I know this is not the way a form should be constructed but I'm trying to
'push' the data into a table to improve speed and a continuous form doesn't
work because being Unbound it doesn't hold more than one record at a time.
Sorry for all the waffle but can you help with this? Have I got the loop
structure right too?
Thanks guys!
Lee