Subform Record

C

CornDog

I know how to create a combobox on a form that calls up a
record based on its selection.

How do make the code so I have a combobox on the mainform
and the record set in a subform. I cant figure out the
reference to the subform.
 
A

Allen Browne

The AfterUpdate of your combo is probably performing a FindFirst on the
RecordsetClone of the form. You can specify the subform instead of the form.

The code will be something like this:

Sub CboMoveTo_AfterUpdate ()
Dim rs As DAO.Recordset

If Not IsNull(Me.cboMoveTo) Then
'Save before move.
If Me.Dirty Then
Me.Dirty = False
End If
'Search in the clone set of the subform.
With Me.[NameOfYourSubformControlHere].Form
Set rs = .RecordsetClone
rs.FindFirst "[CustomerID] = " & Me.cboMoveTo
If rs.NoMatch Then
MsgBox "Not found: filtered?"
Else
'Display the found record in the form.
.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End With
End If
End Sub

For an explanation of the code, see:
http://allenbrowne.com/ser-03.html

For an explanation of the ".Form", bit, see:
http://allenbrowne.com/casu-04.html
 

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