Call a function from a subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I imagine this is a simple issue for someone who knows what they're doing.
I have a form with several checkboxes, etc. for setting up a query define a
recordset for a series of activites assigned to buttons at the bottom of the
form.

To allow more capable users of creating their own queries I created a
subform that will, more or less, allow the user to define their own query.

The form has a function: checkCriteria(DocName) that puts the string
together for the query.

On the subform I created: Public Function MapQCriteria(DocName) which does
the same thing.

When I try to call my MapQCriteria from the parent form (as below) it tells
me "Sub or Function not defined" (the function works fine when called from
the subform)

What am I missing here?

Thanks
David

Private Sub CmdRepPacket_Click()
Dim SqlWhere As String
Dim DocName As String
If FrmMappingQrySub.Visible = False Then
SqlWhere = checkCriteria(DocName)
Else
SqlWhere = MapQCriteria(DocName)
End If
DoCmd.OpenReport "HouseVisitPackets", acViewPreview, , SqlWhere
End Sub
 
Hi,

I belive your public function should be on a stand-alone module, not code
behind a form.

Karrie
 
OregonIzer wrote in message
I imagine this is a simple issue for someone who knows what they're doing.
I have a form with several checkboxes, etc. for setting up a query define a
recordset for a series of activites assigned to buttons at the bottom of the
form.

To allow more capable users of creating their own queries I created a
subform that will, more or less, allow the user to define their own query.

The form has a function: checkCriteria(DocName) that puts the string
together for the query.

On the subform I created: Public Function MapQCriteria(DocName) which does
the same thing.

When I try to call my MapQCriteria from the parent form (as below) it tells
me "Sub or Function not defined" (the function works fine when called from
the subform)

What am I missing here?

Thanks
David

Private Sub CmdRepPacket_Click()
Dim SqlWhere As String
Dim DocName As String
If FrmMappingQrySub.Visible = False Then
SqlWhere = checkCriteria(DocName)
Else
SqlWhere = MapQCriteria(DocName)
End If
DoCmd.OpenReport "HouseVisitPackets", acViewPreview, , SqlWhere
End Sub

A sub or function declared with the public keyword within a form, can
be reached from other code as if it was a form property/method.

So, if the subform control name was for instance frmMySub, then from
the main form, you should be able to call it like this:

SqlWhere = Me!frmMySub.Form.MapQCriteria(DocName)
 
Works perfectly. Thanks.

RoyVidar said:
OregonIzer wrote in message


A sub or function declared with the public keyword within a form, can
be reached from other code as if it was a form property/method.

So, if the subform control name was for instance frmMySub, then from
the main form, you should be able to call it like this:

SqlWhere = Me!frmMySub.Form.MapQCriteria(DocName)
 
Back
Top