FindFirst retrieves wrong record
Hi there,
I have the following code to sync the 'Detailed User Report ALL' form with the selected Username in the combo box in the 'main menu' form, which you then click to sync.
'=======================================
Private Sub cmdSearch_Click()
If IsNull(Me.cmbUserSelect) Then
MsgBox "Please select a UserName to search."
Exit Sub
End If
Dim formname, SyncCriteria As String
Dim f As Form, rs As Recordset
formname = "Detailed User Report ALL form"
If Not SysCmd(acSysCmdGetObjectState, acForm, formname) Then
DoCmd.OpenForm formname
End If
Set f = Forms(formname)
Set rs = f.RecordsetClone
SyncCriteria = BuildCriteria("UserName", dbText, _
Me.cmbUserSelect)
rs.FindFirst SyncCriteria
'MsgBox rs.Fields("UserName") 'to check the Username of the combo box in mainmenu
If rs.NoMatch Then
MsgBox "No match exists!", 64, formname
Else
f.Bookmark = rs.Bookmark
End If
'MsgBox f![UserName] 'check the current Username of the form thats meant to be synchronized.
Me.Visible = False
Set f = Nothing
Set rs = Nothing
End Sub
'=======================================
There are the exact same number of records in the cmbUserSelect combo box as there are in the 'Detailed User Report ALL' form since they refer to the same source. but for some reason the procedure only works for some UserName values and not others. I cant figure out why because I have used this procedure in other parts of my project and works fine. only they are based on the current record in a Datasheet, where as this is based on a combo-box selection. Any help and advice is much appreciated, thank you for your time.
Derek
|