Finding a record in a subForm

B

Bruce Rodtnick

I have a form of song books with a subform on a second tabpage. When I
doubleclick on a song in the sub it pops up a form with all the songs in

all the books available. I want to be able to double click on one of
the songs in the popup form and go to the book AND the song in the
subform. I'm using the following code to get to the book, but I can't
get it to go to the particular song in the subForm. The field for the
Song Name is [Song Name]. Can this be done, and how would I do it?

Bruce Rodtnick

CODE TO GET TO THE BOOK:

Private Sub SongName_DblClick(Cancel As Integer)
Dim FormName As String, SyncCriteria As String
Dim F As Form, rs As Object

'Set the formname to "Books," the form that will be
'synchronized.
FormName = "Books"

DoCmd.OpenForm FormName

'Define the form object and Recordset object for
'the Products form.
Set F = Forms(FormName)
Set rs = F.Recordset.Clone

'Define the criteria used for the synchronization.
' some of the product names contain an apostrophe. Although the
following
' if statement doesn't need the else clause, it does permit the
correct syntax

If InStr(1, Me.BookName, "'") > 0 Then
SyncCriteria = "[Book Name] =" & Chr(34) & Me!BookName & Chr(34)

Else
SyncCriteria = "[Book Name] ='" & Me!BookName & "'"
End If

DoCmd.Close acForm, Me.Name

'Synchronize the corresponding record in the Products form to
'the current record in the subform.
rs.FindFirst SyncCriteria

'If a record exists in the Products form, find the
'matching record.
If rs.EOF Then
MsgBox "No match exists!", 64, FormName
Else
F.Bookmark = rs.Bookmark
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top