I have a main form with a subform. The main form is bound to a table, which has a primary key of ID1 and a foreign key of ID2.
The main form / subform relationship is set up on ID2, so the main form will show 1 record at a time, and then the subform will show all related records that match ID2 for the current record on the main form.
I'm trying to use a command button within the subform records so that I can move the main form to that particular record in the subform using the ID1 field:
Private Sub cmdLoadAssess_Click()
Dim rs As DAO.Recordset
Dim frm As Form
Set frm = Me.Parent
Set rs = frm.RecordsetClone
rs.FindFirst "ID1=" & Me.ID1
If _
Not rs.NoMatch _
Then
Debug.Print "Match found for " & Me.ID1
frm.Bookmark = rs.Bookmark
Else
Debug.Print "No match found for " & Me.ID1
End If
End Sub
Unfortunately this seems to only be able to find a match on ID1 for the current record in the main form (which is pointless, since the main form is already there!)
I know these records exists (they're right there in subform), and those Debug.Print lines tell me ID1 is being passed from the subform. What am I missing here?
Edit:
After doing a rs.MoveLast and then checking the cloned recordset's rs.RecordCount and rs!ID, it seems that only the current record on the main form has been cloned for the recordset rather than the whole table that the main form is bound to. Why is it not cloning the whole recordset of the main form?
rs.MoveLastandDebug.Print rs.RecordCount- are you sure the main form has the complete table as record source, not just one record? Can you manually navigate in the main form? - Andre.Filterproperty of the form. So perhaps the recordset is essentially already filtered before I try to look for other records inside it. - Matt Hallfrm.Filter = "ID1=" & Me.ID1instead of using Bookmarks. - Andrefrm.Filterand nothing else, i.e. don't useRecordsetClone? You couldn't expand that in answer could you? I only ask because just setting thefrm.Filterdoesn't seem to move the form to a record. - Matt Hall