GoTo Record in subform datasheet from a search on main form

jaredg16

New member
Local time
Today, 16:14
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]
 
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
 
I'd do this. No hugely different, but a little shorter. Avoids clones and bookmarks.
Code:
Private Sub SearchRecordsButton_Click()
  IF NOT Trim(Me.SearchLastName & "") = "" then
    With Me.SubForm_StudentList.Form.Recordset
      .FindFirst "lastname = '" & Me.SearchLastName & "'"
      IF .NoMatch Then ShowSearchErr "Match not found for: '" & Me.SearchLastName & "'"
    End With
  Else
    ShowSearchErr "Invalid Search Criteria"
  End If
End Sub

Private Sub ShowSearchErr(msg as string)
  Me.SearchLastName.SetFocus
  MsgBox msg, vbExclamation, "Search Error"
End Sub
 

Users who are viewing this thread

Back
Top Bottom