event calls seemingly unrelated procedure

brharrii

Registered User.
Local time
Today, 14:58
Joined
May 15, 2012
Messages
272
I have two forms:

frmOpeartions
frmManagers

frmOperations allows the user to assign a manager to an operation by selecting the manager record from a combobox. Occasionally the user may need to setup a new Manager record if one hasn't been setup already. In this case there is a "New" "button" (it's actually a label with an on click event) that the user can click to open frmManagers and add the new manager record.

The code to open frmManagers is:

Code:
Private Sub lblNewManager_Click()
    DoCmd.OpenForm "frmManagers", acNormal, , , acFormAdd, acDialog
    Forms!frmManagers!cboMoveTo.Visible = False
    Forms!frmManagers!lblManagers.Visible = True
End Sub


Once frmManagers is open the user creates the new Manager record and then closes the form using a similar label with an on click event:

Code:
Private Sub lblClose_Click() 
DoCmd.Close acForm, "frmManagers", acSaveNo
End Sub

frmMangers also has an OnClose event that will refresh any comboboxes on other forms that refer to tblManagers to make sure that new Manager records will be available immediately for the user to choose from:


Code:
Private Sub Form_Close()
    If CurrentProject.AllForms("frmPlants").IsLoaded Then
        Forms!frmPlants!cboPlantManager.Requery
        Forms!frmPlants!cboQCManager.Requery
        Forms!frmPlants!cboCorporateQAContact.Requery
    End If
 
    If CurrentProject.AllForms("frmOperations").IsLoaded Then
        Forms!frmOperations!cboCorporateQAContact.Requery
    End If
 
End Sub


So the problem comes when the user clicks the Close label (acting like a button) on the frmManagers. The code successfully closes the form and the on close event successfully refreshes any comboboxes on forms that may be open, but then for some reason it attempts to run again or perhaps continue running the onClick event that opens frmManagers. Since the form is already closed it gets hung up on trying to change the visible properties of the controls and the code fails.

I'm sure I've done something wrong, just not sure what it is.

Any ideas?

Thanks!
 
When you use acDialog to open the form, no code below that line runs until that form is closed or hidden.
 
ah I see, are you aware of a way that i can open the form in dialog mode and still manipulate the control visible property?

There is a combobox at the top of frmManagers that acts as a record selector. If the form is accessed from the main navigation form I want the user to be able to see and use this combobox. If the form is accessed from frmOperations, then then the form is opened as acFormAdd and the user will only be able to add new records. The combobox thus is not needed and returns an error if used. I was hoping to hide or somehow disable the combobox to keep the form simple.

acDialog is a preference of mine. Maybe that is what I'll ultimately need to change... but I think that the transition between the two forms is more intuitive using acDialog which is why I have it setup that way.
 
I just figured out how to do this:

I changed the form property: "Pop up" under "Other", to yes.

I can then set the open form code to acNormal instead of acDialog and I still get a windowed view of the form.

Thanks again for pointing me in the right direction pbaldy :)
 
No problem. Sorry for the delay; it's been a hectic day.
 
No worries. I'm always appreciative for your insight. I wouldn't have been able to figure the rest of it out if not for you pointing out why it was breaking in the first place.

Thanks again :)
 

Users who are viewing this thread

Back
Top Bottom