GoTo Record in subform datasheet from a search on main form

jaredg16

New member
Local time
Today, 03:35
Joined
Feb 3, 2007
Messages
5
Okay, so as the photo below shows, I have a main form with a subform in it.

https://filestogeaux.lsu.edu/public/download.php?FILE=jaredg16/77529FNbGMk

Currently, when you search for a last name in the search box, it calls the following OnClick event procedure to go to that record in the main form.

'------------------------------
' Search for Last Name Box
'------------------------------
Private Sub SearchRecordsButton_Click()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[lastname] = '" & Me![SearchLastName] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

So far so good, but what I would also like to do is not only to go to that record in the main form as it currently does, but I'd also like it to go to that same record in the subform datasheet. How can I do this?

Thanks in advance!
[/SIZE][/SIZE]
 
Why would you have the same details in the subform and mainform?
 
Because that's how the client wants it. I advised against as well, but they want the "List" tab to display all of the records, and from that list they select the record they want and move to the other tabs for that record's information.

Any ideas on a solution to the above posting?

Jared
 
So guys... I was able to resolve the problem above... check out the code below:


-------------------------------------------------

'------------------------------
' Search for Last Name Box
'------------------------------
Private Sub SearchRecordsButton_Click()

' Find the record that matches the control.
Dim rs As Object

Set rs = Me.SubForm_StudentList.Form.RecordsetClone
rs.FindFirst "[lastname] = '" & Me![SearchLastName] & "'"

'Check SearchLastName for Null value or Nill Entry first.
If Not Trim(Me![SearchLastName]) = "" Then
Me.SubForm_StudentList.Form.Bookmark = rs.Bookmark
Else
MsgBox "Please enter search criteria.", vbOKOnly, "Error"
Me![SearchLastName].SetFocus
Exit Sub
End If

'If matching record found, this sets focus in SearchLastName field
'and shows msgbox and clears search control
If Not rs.NoMatch Then
Me.SubForm_StudentList.Form.Bookmark = rs.Bookmark
'If value not found sets focus back to SearchLastName and shows msgbox
Else
MsgBox "Match not found for: " & Me![SearchLastName] & "", , "Error"
Me![SearchLastName].SetFocus
End If
Me![SearchLastName] = ""

End Sub
--------------------------------------------

This works wonderfully.

Jared
 

Users who are viewing this thread

Back
Top Bottom