I've searched the archives and recent posts, but have not found exactly the solution I need. Your help will be much appreciated!
I need to add new or update a record in a table. In the code below, the Else part works. It's the first part I just can't get right. What I'm trying to say is for each CRN in qryXLst (and I've tried For Each but can't get that right), add new record using the CRN from qryXLst and info from current form.
'Instructor #2
If Me!cboInstr2 <> "" And Me!cboInstr2 <> "STAFF" Then
rs.FindFirst "Sess = '02' "
If rs.NoMatch Then
Dim qryXLst As String
qryXLst = "SELECT [AllSections].[CRN] " & _
"FROM AllSections " & _
"WHERE [AllSections].[XLst]= '" & Me!XLst & "' ;"
DoCmd.OpenQuery qryXLst
Do While Not rs.EOF
rs.AddNew
rs!CRN = qryXLst
rs!Sess = "02"
rs!InstrName = Me!cboInstr2
rs!LName = Me!cboInstr2.Column(1)
rs!FName = Me!cboInstr2.Column(2)
rs!PInd = ""
rs!Sess = "02"
rs!DivNum = Me!txtDivNum
rs!XLst = Me!XLst
rs.MoveNext
Loop
Else
Do While Not rs.EOF
rs.Edit
rs!InstrName = Me!cboInstr2
rs!LName = Me!cboInstr2.Column(1)
rs!FName = Me!cboInstr2.Column(2)
rs!PInd = ""
rs!Sess = "02"
rs!DivNum = Me!txtDivNum
rs.Update
rs.MoveNext
Loop
End If
I need to add new or update a record in a table. In the code below, the Else part works. It's the first part I just can't get right. What I'm trying to say is for each CRN in qryXLst (and I've tried For Each but can't get that right), add new record using the CRN from qryXLst and info from current form.
'Instructor #2
If Me!cboInstr2 <> "" And Me!cboInstr2 <> "STAFF" Then
rs.FindFirst "Sess = '02' "
If rs.NoMatch Then
Dim qryXLst As String
qryXLst = "SELECT [AllSections].[CRN] " & _
"FROM AllSections " & _
"WHERE [AllSections].[XLst]= '" & Me!XLst & "' ;"
DoCmd.OpenQuery qryXLst
Do While Not rs.EOF
rs.AddNew
rs!CRN = qryXLst
rs!Sess = "02"
rs!InstrName = Me!cboInstr2
rs!LName = Me!cboInstr2.Column(1)
rs!FName = Me!cboInstr2.Column(2)
rs!PInd = ""
rs!Sess = "02"
rs!DivNum = Me!txtDivNum
rs!XLst = Me!XLst
rs.MoveNext
Loop
Else
Do While Not rs.EOF
rs.Edit
rs!InstrName = Me!cboInstr2
rs!LName = Me!cboInstr2.Column(1)
rs!FName = Me!cboInstr2.Column(2)
rs!PInd = ""
rs!Sess = "02"
rs!DivNum = Me!txtDivNum
rs.Update
rs.MoveNext
Loop
End If