Referring to controls on a form from a subform - weird issue

H

HeislerKurt

I'm trying to hide/show two labels on a popup form (frmPopup) based on
how the form was called from a subform.

The subform (fsubPeople) is in continuous view. It's a sub sub form
(i.e., MainForm > SubForm1 > fsubPeople). There's a command button in
the Detail section, and a command button in the Form Header.

If the user clicks on the command button in the Detail section (which
opens frmPopup filtered to a matching record), things work: I can set
and hide the labels correctly. But if the user clicks on the command
button in the Form Header (which opens frmPopup in acFormAdd, acDialog
mode), I get the error:

"... can't find the form 'frmPopup' referred to a macro or visual
basic expression."

Any idea how I can correctly refer to the label controls when the form
is opened in acFormAdd mode?

Thank you!

----

Code from button in Detail Section (hiding/showing the labels works!)

###

Private Sub cmdEditPersonInfo_Click()

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
DoCmd.openForm "frmPopup"

Forms!frmPopup.RecordSource = "SELECT DISTINCTROW tblPeople.* " & _
"FROM tblPeople " & _
"WHERE ((tblPeople.PersonID=Forms!frmPatients!
frmReferrals.Form!fsubPeople.Form!PersonID));"

Forms!frmPopup.cmdAssignToPatient.Visible = False
Forms!frmPopup.cmdSave.Visible = True

End Sub

###

Code from button in Form Header Section (this causes the error)

###

Private Sub cmdAssignNewPerson_Click()

DoCmd.openForm "frmPopup", , , , acFormAdd, acDialog

Forms!frmPopup.cmdAssignNewPerson.Visible = True
Forms!frmPopup.cmdSave.Visible = False

End Sub

###
 
A

Anthos

When a form is opened in Dialog mode, all code is stoped from the
calling module until the form is closed again.

So think of the flow like this....


Open Form in Dialog
-> STOP CODE UNTIL FORM CLOSES

{USER CLOSES FORM}

Code continues onto the next line after the form is closed,

The reason it is working with the other form, is that you aren't
calling it in Dialog mode, and as such the code is continuing.


Hope that helps clear up why the error is occuring.

A nice quick method of using this is to utilise a Global Variable for
the short period of time between when you click the button and don't.

Thus when the form opens, it looks at the variable value, and
determines whether it needs to show the cmdbutton or not.

Hope this gives you some idea's on how to move forward,


Kind Regards
Anthony Moore


IT Excellence
 

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


Top