Create VB line in a loop

pekajo

Registered User.
Local time
Tomorrow, 02:41
Joined
Jul 25, 2011
Messages
135
HI,

Hope you can help. I would like to create a loop where I change the VB line with the loop number. IE

rs2.AddNew
rs2![SDPhone] = Val(stext)
rs2![SDQty] = rs1![P1Qry]
rs2![SDName] = rs1![P1Name]
rs2![SDSKU] = rs1![P1SKU]
rs2![SDPID] = rs1![PID]

I would like to change the P1 where the loop number changes the numeric number. So in pass one it will be P1 next time P2 next P3 and so on.
The P1 refers to a field name.

Thanks for any help.

Regards
Peter
 
Try this:

Code:
Dim i as integer
Dim sField1 as string
Dim sField2 as string
Dim sField3 as string
i = 0
dim maxvalue as integer
maxvalue = [enter your max number of fields here]
Do until i = maxvalue - 1
sfield1 = "P" & i & "Qry"
sField2 = "P" & i & "Name"
sField3 = "P" & i & "SKU"
   rs2.AddNew
   rs2![SDPhone] = Val(stext)
   rs2![SDQty] = rs1.Fields(sfield1)
rs2![SDName] = rs1.Fields(sfield2)
rs2![SDSKU] = rs1.Fields(sField3)
rs2![SDPID] = rs1![PID]
i = i + 1
Loop
 
HI,

Hope you can help. I would like to create a loop where I change the VB line with the loop number. IE

rs2.AddNew
rs2![SDPhone] = Val(stext)
rs2![SDQty] = rs1![P1Qry]
rs2![SDName] = rs1![P1Name]
rs2![SDSKU] = rs1![P1SKU]
rs2![SDPID] = rs1![PID]

I would like to change the P1 where the loop number changes the numeric number. So in pass one it will be P1 next time P2 next P3 and so on.
The P1 refers to a field name.

Thanks for any help.

Regards
Peter

Create a variable

Dim entIcing As Integer

Then refer to it using

rs1("P" & intCount)
 

Users who are viewing this thread

Back
Top Bottom