When I run the following code once, it works fine, when I run it for a second time I get an Invalid Opperation message at this line
.FindFirst "[ActivityID] = " & AcIDRow & ""
which appears to suggest the .MoveLast is not working
Prior to this part of the Code a new record is added to the Listbox [SchemesAttached] this code then finds the new record in the listbox which then opens a [FrmSchemesSocialActivity] based on the row selected in the listbox
I am pulling my hair out as I can't find why it works once but on a second time, any thoughts
Dim rs As DAO.Recordset
Dim AcIDRow As String
Dim MyVarBM As Long
Select Case Forms![FrmSchemes].NewSchemeID 'NewSchemeID from the newly created record
Case 46, 48, 54, 71, 81, 69 'Social
Forms![FrmSchemes]![SchemesAttached].Requery
AcIDRow = DMax("[ActivityID]", "tblAccountSchemes")
Forms![FrmSchemes].ActivityID = AcIDRow
If Forms![FrmSchemes]![SchemesAttached].Visible = False Then
Forms![FrmSchemes]![SchemesAttached].Visible = True
Forms![FrmSchemes]![SchemesAttached].RowSource = "QrySearchbyScheme"
End If
Set rs = Forms![FrmSchemes]![SchemesAttached].Recordset
With rs
.MoveLast
.FindFirst "[ActivityID] = " & AcIDRow & ""
MyVarBM = .AbsolutePosition + 1 'returns the row # of the offending record
Forms![FrmSchemes]![SchemesAttached].Selected(MyVarBM) = True 'selects the offending row
If .NoMatch Then
MsgBox "No Match Found"
End If
End With
DoCmd.OpenForm "FrmSchemesSocialActivity", acNormal
End Select
Set rs = Nothing 'Deassign all objects
.FindFirst "[ActivityID] = " & AcIDRow & ""
which appears to suggest the .MoveLast is not working
Prior to this part of the Code a new record is added to the Listbox [SchemesAttached] this code then finds the new record in the listbox which then opens a [FrmSchemesSocialActivity] based on the row selected in the listbox
I am pulling my hair out as I can't find why it works once but on a second time, any thoughts
Dim rs As DAO.Recordset
Dim AcIDRow As String
Dim MyVarBM As Long
Select Case Forms![FrmSchemes].NewSchemeID 'NewSchemeID from the newly created record
Case 46, 48, 54, 71, 81, 69 'Social
Forms![FrmSchemes]![SchemesAttached].Requery
AcIDRow = DMax("[ActivityID]", "tblAccountSchemes")
Forms![FrmSchemes].ActivityID = AcIDRow
If Forms![FrmSchemes]![SchemesAttached].Visible = False Then
Forms![FrmSchemes]![SchemesAttached].Visible = True
Forms![FrmSchemes]![SchemesAttached].RowSource = "QrySearchbyScheme"
End If
Set rs = Forms![FrmSchemes]![SchemesAttached].Recordset
With rs
.MoveLast
.FindFirst "[ActivityID] = " & AcIDRow & ""
MyVarBM = .AbsolutePosition + 1 'returns the row # of the offending record
Forms![FrmSchemes]![SchemesAttached].Selected(MyVarBM) = True 'selects the offending row
If .NoMatch Then
MsgBox "No Match Found"
End If
End With
DoCmd.OpenForm "FrmSchemesSocialActivity", acNormal
End Select
Set rs = Nothing 'Deassign all objects