I have a form based on a query with multiple primary keys. I have Company, MemberNumber and DateVisit as the 3 keys. I want to use a combo box to select a member and have been able to do it with the code below, which loops through every record to check whether the selected on exists and then bookmarks it. I would rather use an SQL statement to select the required record, but that doesn't seem to be available with RecordsetClone, and FindFirst only caters for a single primary key, or am I wrong.
Code:
Dim NumRec As Integer
Dim strSQL As String
Dim response As Boolean
Dim vntPosition As Variant
'Declare and instantiate a recordset
Dim rst As Recordset
Set rst = Me.RecordsetClone
'Establish the connection and cursor type,
'and open the recordset
rst.MoveFirst
Do Until rst.EOF
wsCompany = rst("Company")
wsMemberNumber = rst("MemberNumber")
wsDateVisit = rst("DateVisit")
If wsDateVisit = lstClinicVisit.Column(0) _
And wsMemberNumber = lstClinicVisit.Column(2) _
And wsCompany = lstClinicVisit.Column(1) _
Then
'Record found for this member for this day
'Store details for Edit mode
Me.DateVisit.SetFocus
Me.Bookmark = rst.Bookmark
rst.Close
Set rst = Nothing
Exit Sub
Else
rst.MoveNext
End If
Loop
'No records found for this member
'Clear details for Edit Mode
MsgBox "No record found for this member for this day! Try again or use scroll keys"
Me.MemberNumber = Null
Me.Company = Null
Me.DateVisit = Null
Me.DateGP = Null
Me.txtName = ""
Me.txtAddress = ""
Me.Scan = Null
Me.Condition = Null
Me.Outcome = Null
Me.Investigation = Null
Me.Charge = Null
Me.DateVisit.SetFocus
rst.Close
Set rst = Nothing