I'm trying to write a query that takes the job number (existing field) and the number of records field, NbrRec (typed in number on form) and updates ATT to 0 and Verizon to 1. I have 704 records that match the job number and I enter 624 in NbrRec. I would like only 624 of the ATT records updated to 0 and 624 of the Verizon records to 1. (Essentially I don't have enough ATT air cards but I do have enough verizon.) I tried breaking it down step by step, but when I put it together, it doesn't work. This is my code:
Private Sub btn_ATT_VZN_Click()
On Error GoTo ATT_VZN_Err
Dim strSQL1, Q1 As String
Dim strSQL2, Q2 As String
Dim strSQL3, Q3 As String
strVar = [Forms]![frmScheduleNav]![NavigationSubform].[Form]![NbrRec]
strSQL1 = "SELECT tblScheduleReport.ATT, tblScheduleReport.Verizon, tblScheduleReport.[Datascan Job No#] FROM tblScheduleReport WHERE (((tblScheduleReport.[DATASCAN JOB NO#]) = [Forms]![frmScheduleNav]![NavigationSubform].[Form]![FrmtblSchedRep]![DATASCAN JOB NO#])) ORDER BY tblScheduleReport.ATT DESC;"
strSQL2 = "SELECT TOP" & strVar & "Q1.ATT, Q1.Verizon FROM Q1;"
strSQL3 = "UPDATE Q2 SET Q2.ATT = 0, q2.Verizon = 1"
ATT_VZN_EXIT:
Exit Sub
ATT_VZN_Err:
MsgBox Err.Number & Err.Description
Resume ATT_VZN_EXIT
End Sub
Private Sub btn_ATT_VZN_Click()
On Error GoTo ATT_VZN_Err
Dim strSQL1, Q1 As String
Dim strSQL2, Q2 As String
Dim strSQL3, Q3 As String
strVar = [Forms]![frmScheduleNav]![NavigationSubform].[Form]![NbrRec]
strSQL1 = "SELECT tblScheduleReport.ATT, tblScheduleReport.Verizon, tblScheduleReport.[Datascan Job No#] FROM tblScheduleReport WHERE (((tblScheduleReport.[DATASCAN JOB NO#]) = [Forms]![frmScheduleNav]![NavigationSubform].[Form]![FrmtblSchedRep]![DATASCAN JOB NO#])) ORDER BY tblScheduleReport.ATT DESC;"
strSQL2 = "SELECT TOP" & strVar & "Q1.ATT, Q1.Verizon FROM Q1;"
strSQL3 = "UPDATE Q2 SET Q2.ATT = 0, q2.Verizon = 1"
ATT_VZN_EXIT:
Exit Sub
ATT_VZN_Err:
MsgBox Err.Number & Err.Description
Resume ATT_VZN_EXIT
End Sub