RecordsetClone and Subforms

B

bh

I'm trying to create a search form, which can be called by multiple forms.
I pass in the calling form name through the OpenArgs and create a
recordsetclone for searching accordingly. This works fine, if the calling
form is a main form as (Case "Courts") follows, however, if I pass through a
subform (Case "County"), I get an error stating "Object doesn't support this
property or method":

DIM rst as DAO.Recordset
Select Case Me.OpenArgs
Case "Courts"
SET rst = Forms!frmCourts.RecordsetClone
Case "County"
SET rst = Forms!frmCounty!frmCountySubform.RecordsetClone
End Select

If anyone has run into this in the past, please help. Thanks in advance for
your assistance.

bh
 
D

Dirk Goldgar

In
bh said:
I'm trying to create a search form, which can be called by multiple
forms. I pass in the calling form name through the OpenArgs and
create a recordsetclone for searching accordingly. This works fine,
if the calling form is a main form as (Case "Courts") follows,
however, if I pass through a subform (Case "County"), I get an error
stating "Object doesn't support this property or method":

DIM rst as DAO.Recordset
Select Case Me.OpenArgs
Case "Courts"
SET rst = Forms!frmCourts.RecordsetClone
Case "County"
SET rst = Forms!frmCounty!frmCountySubform.RecordsetClone
End Select

If anyone has run into this in the past, please help. Thanks in
advance for your assistance.

Alex Dybenko has posted a corrected syntax for your subform reference.
But do you have to make this general, so that the function can't assume
the names of the form and subform controls involved? In that case, you
pass via OpenArgs a string that would be a correct "bang path" to the
form or subform whose recordset you want to work with. For example,

"frmCourts"
"frmCounty!frmCountySubform"
"frmCounty!frmCountySubform!frmCountSubSubForm"

The code in your search form would then use the Split function to parse
this into an array of 1 to N elements. You could then work with that
array to get to the deepest form object. Something like this:

' Error-handling left as an exercise ...

Dim rst as DAO.Recordset
Dim frm As Access.Form
Dim astrForms() As String
Dim I As Integer

astrForms = Split(Trim(Me.OpenArgs & vbNullString), "!")

If UBound(astrForms) < 0 Then
MsgBox "Form argument required!"
Exit Sub
End If

Set frm = Forms(astrForms(0))
For I = 1 to UBound(astrForms)
Set frm = frm.Controls(astrForms(I)).Form
Next I

Set rst = frm.RecordsetClone

' ... and off you go!
 

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