Having problem with loops. The inner loop updates a table. The outer loop pulls the record number from the "tblChangeOrderTable_Edit_Count" and is assigned to strRecordID . The inner loop uses strRecordID to find the right record. I keep getting errors like (Object variable or With Block variable not set.)
Need help in getting the loops right.
Richard
Need help in getting the loops right.
Richard
Code:
[FONT=Calibri]Private Sub btnClose_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)[/FONT]
[FONT=Calibri]Dim db As Database, rs As Recordset, rs1 As Recordset2[/FONT]
[FONT=Calibri]Dim Criteria As String[/FONT]
[FONT=Calibri]Dim strAns1 As String[/FONT]
[FONT=Calibri]Dim strAns2 As String[/FONT]
[FONT=Calibri]Dim strCount1 As String[/FONT]
[FONT=Calibri]Dim strAns3 As String[/FONT]
[FONT=Calibri]Dim strRecordID As String[/FONT]
[FONT=Calibri]Dim strCTR As String[/FONT]
[FONT=Calibri]Dim CTR As String[/FONT]
[FONT=Calibri]DoCmd.SetWarnings False[/FONT]
[FONT=Calibri]DoCmd.OpenQuery "qryChangeOrderTable_Edit1_Delete"[/FONT]
[FONT=Calibri]DoEvents[/FONT]
[FONT=Calibri]DoCmd.OpenQuery "qryChangeOrderTable_Edit1"[/FONT]
[FONT=Calibri]DoEvents[/FONT]
[FONT=Calibri]strCTR = DCount("*", "tblChangeOrderTable_Edit_Count")[/FONT]
[FONT=Calibri]Debug.Print strCTR[/FONT]
[FONT=Calibri]DoCmd.SetWarnings True[/FONT]
[FONT=Calibri]If Me.Frame36 = 1 Then 'Single Page[/FONT]
[FONT=Calibri]‘ Donothing[/FONT]
[FONT=Calibri]Else[/FONT]
[FONT=Calibri]Set db = CurrentDb[/FONT]
[FONT=Calibri]Set rs1 = db.OpenRecordset("tblChangeOrderTable_Edit_Count", DB_OPEN_DYNASET)[/FONT]
[FONT=Calibri]If Me.cboTableNoTable = "T" Then[/FONT]
[FONT=Calibri]Do[/FONT]
[FONT=Calibri]Open "tblChangeOrderTable_Edit_Count" For Random As #1[/FONT]
[FONT=Calibri]Do While Not EOF(1)[/FONT]
[FONT=Calibri]strRecordID = rs("[ChangeOrderDataid]")[/FONT]
[FONT=Calibri]Set rs = db.OpenRecordset("tblChangeOrderData", DB_OPEN_DYNASET)[/FONT]
[FONT=Calibri]Open "tblChangeOrderData" For Random As #2[/FONT]
[FONT=Calibri]Do While Not EOF(2)[/FONT]
[FONT=Calibri]rs.Edit[/FONT]
[FONT=Calibri]If rs("ChangeOrderDataid") = strRecordID Then rs("ChangeOrderDate") = [/FONT][FONT=Calibri]Me!txtChangeOrderDate[/FONT]
[FONT=Calibri]If rs("ChangeOrderDataid") = strRecordID Then rs("ContractorDataID") = [/FONT][FONT=Calibri]Me!cboContractor[/FONT]
[FONT=Calibri]Debug.Print rs("ChangeOrderDate")[/FONT]
[FONT=Calibri]Debug.Print rs("ContractorDataID")[/FONT]
[FONT=Calibri]rs.Update[/FONT]
[FONT=Calibri]rs.MoveNext[/FONT]
L[FONT=Calibri]oop[/FONT]
[FONT=Calibri]Close #2[/FONT]
[FONT=Calibri]rs.MoveNext [/FONT]
L[FONT=Calibri]oop[/FONT]
[FONT=Calibri]Close #1[/FONT]
[FONT=Calibri]Loop[/FONT]
[FONT=Calibri]End If[/FONT]
[FONT=Calibri][SIZE=3][FONT=Verdana][SIZE=2] [FONT=Calibri][SIZE=3]S[/SIZE][/FONT][/SIZE][/FONT]et db = Nothing[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Set rs = Nothing[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Set rs1 = Nothing [/SIZE][/FONT]
[FONT=Calibri][SIZE=3]End If[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]End Sub[/SIZE][/FONT]
Last edited: