I have a form that uses an unbound combobox to select the record displayed. The user box selects a ProjectID and the form shows information about the project. This form has a recordsource that uses a query based on a single table. My code here is working fine.
When I attempt to open the form and pass the project ID to this form, the search in the recordset clone does not find the record. It does populate the combo box. But, if the called form was already open, then the recordset clone does find the record.
I have been unable to figure this one out. Please help
Here is the code:
When I attempt to open the form and pass the project ID to this form, the search in the recordset clone does not find the record. It does populate the combo box. But, if the called form was already open, then the recordset clone does find the record.
I have been unable to figure this one out. Please help
Here is the code:
Code:
Public Function OpenMaintainShows(iRecordID As Long) As Boolean
'** I am passing in the Record ID that I want to display on the target form (frmShows_Maintain2)
Dim rs As Object
Dim frm As Form
If IsObjectOpen("frmShows_Maintain2", acForm) Then '** This calls a function to see if the form is already open
Forms("frmShows_Maintain2").SetFocus
Forms("frmShows_Maintain2").cmbShows = iRecordID
Else
DoCmd.OpenForm FormName:="frmShows_Maintain2", View:=acNormal
Forms("frmShows_Maintain2").cmbShows = iRecordID
End If
'***************************************************************************************************
'** If the target form is open, then this code will work
'** If the target form is closed, the code opens the form, the value in the combo box is updated, but
'** the record is not retrieved
'***************************************************************************************************
Set frm = Forms("frmShows_Maintain2")
Set rs = frm.RecordsetClone
Debug.Print frm.cmbShows.Value
rs.FindFirst "ShowID = " & CInt(frm.cmbShows.Value)
If rs.NoMatch Then
Debug.Print "did not find record"
Else
frm.Bookmark = rs.Bookmark
End If
End Function