Adam McReynolds
Registered User.
- Local time
- Yesterday, 19:53
- Joined
- Aug 6, 2012
- Messages
- 129
I need a loop through a text box to duplicate the current form as many times as the text box designates. A loop with SQL Insert is what I was thinking would work. The code I have crashes the DB. Maybe it is stuck somehow in an infinite loop? Here is what I have so far:
Private Sub Command325_Click()
Dim Check, Counter
IntValue = Text410
Check = True: Counter = 0
Do ' Outer loop.
Do While Counter < Me.Text410.Value ' Inner loop.
Counter = Counter + 1 ' Increment Counter.
If Counter = Me.Text410.Value Then ' If condition is True.
Check = False ' Set value of flag to False.
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tbl_module_repairs ([Customer], [Customer_Contact], [end_user], [system_of_origin], [Pickup_Date], [aps_rma], [po_num], [incoming_disposition], [status], [pickup_entity], [repair_tech]) VALUES ('" & Me!Customer & "','" & Me!Combo361 & "', '" & Me!In_Destination_System & "', '" & Me!In_System_of_Origin & "', '" & Me!PickUp_Date & "', '" & Me!APS_RMA & "', '" & Me!PO_No & "', '" & Me!IncomingDisposition & "', '" & Me!Status & "', '" & Me!Pickup_Entity & "', '" & Me!Combo392 & "');"
DoCmd.SetWarnings True
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately.
DoCmd.GoToRecord , "frm_Module_Repairs_Inbound", acNext
DoCmd.OpenForm "frm_Module_Repairs_Quick_Update_Form", acFormDS
DoCmd.GoToRecord acDataForm,"frm_Module_Repairs_Quick_Update_Form",acLast
End Sub
Private Sub Command325_Click()
Dim Check, Counter
IntValue = Text410
Check = True: Counter = 0
Do ' Outer loop.
Do While Counter < Me.Text410.Value ' Inner loop.
Counter = Counter + 1 ' Increment Counter.
If Counter = Me.Text410.Value Then ' If condition is True.
Check = False ' Set value of flag to False.
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tbl_module_repairs ([Customer], [Customer_Contact], [end_user], [system_of_origin], [Pickup_Date], [aps_rma], [po_num], [incoming_disposition], [status], [pickup_entity], [repair_tech]) VALUES ('" & Me!Customer & "','" & Me!Combo361 & "', '" & Me!In_Destination_System & "', '" & Me!In_System_of_Origin & "', '" & Me!PickUp_Date & "', '" & Me!APS_RMA & "', '" & Me!PO_No & "', '" & Me!IncomingDisposition & "', '" & Me!Status & "', '" & Me!Pickup_Entity & "', '" & Me!Combo392 & "');"
DoCmd.SetWarnings True
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately.
DoCmd.GoToRecord , "frm_Module_Repairs_Inbound", acNext
DoCmd.OpenForm "frm_Module_Repairs_Quick_Update_Form", acFormDS
DoCmd.GoToRecord acDataForm,"frm_Module_Repairs_Quick_Update_Form",acLast
End Sub