Referencing subforms

G

Guest

How would I reference a subform that exists on a tab control which exists on
a main form?

Here's what I've written:

Dim db As Database
Dim rs As Recordset
Dim strsql1 As String
Dim qry As QueryDef

Set db = CurrentDb
Set qry = db.QueryDefs("QryEducatorLogistics")
Set rs = qry.OpenRecordset(dbOpenDynaset)
'strsql1 = Me!Combo47
rs.FindFirst "[REVIEW_COURSE]= '" & Me![Combo47] & "' "
If rs.NoMatch Then
MsgBox "No Entry Found.", vbInformation
Else
Forms!FrmEducatorInformationMain!Pages![CURRENT TRAVEL
ARRANGEMENTS]![FrmEducatorLogistics subform].Bookmark = rs.Bookmark
End If

Thanks
Elyse
 
M

Marshall Barton

elyse said:
How would I reference a subform that exists on a tab control which exists on
a main form?

Here's what I've written:

Dim db As Database
Dim rs As Recordset
Dim strsql1 As String
Dim qry As QueryDef

Set db = CurrentDb
Set qry = db.QueryDefs("QryEducatorLogistics")
Set rs = qry.OpenRecordset(dbOpenDynaset)
'strsql1 = Me!Combo47
rs.FindFirst "[REVIEW_COURSE]= '" & Me![Combo47] & "' "
If rs.NoMatch Then
MsgBox "No Entry Found.", vbInformation
Else
Forms!FrmEducatorInformationMain!Pages![CURRENT TRAVEL
ARRANGEMENTS]![FrmEducatorLogistics subform].Bookmark = rs.Bookmark
End If


The recordset you've opened will probably have different
bookmarks than the form's RecordSource table/query, so I
would expect that to have problems.

If the code is running in the main form (the tab control is
irrelevant), then the code would be more like this:

With Me.[FrmEducatorLogistics subform].Form.RecordsetClone
.FindFirst "[REVIEW_COURSE]= '" & Me![Combo47] & "' "
If .NoMatch Then
MsgBox "No Entry Found.", vbInformation
Else
Me.[FrmEducatorLogistics subform].Form.Bookmark _
=.Bookmark
End If
End With
 
D

David C. Holley

Create a global variable glbResponse. In the AfterUpdate() event of the
form that captures the new record, set glbResponse to the VBA constant
DATA_ERRADDED
Then in the OnNotInListFunction add the statement response = glbResponse.
DATA_ERRADDED indicates that a record was added, requery the combo box
and display it.

My actual implementation is over 7 years old. The technique above is the
way I would do it now, but may require some tweaking itself.

David H
 

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

Similar Threads

Not Valid Bookmark Error 1
Problems Refreshing fields after "No Entry Found" 1
Find First 1
Bookmark Issue 7
FindFirst 3
Recordsets and datbases 1
Compile Error - Don't know WHY? 6
System resource exceeded 1

Top