Flow of control in VBA Question - Userform Interaction

  • Thread starter Thread starter Alan
  • Start date Start date
A

Alan

Hi All,

I have a situation that simplifies to the code below.

My question is:

When the userform unloads due to the admin button being clicked, and
the correct password being entered, does control go back to the
Workbook_Open code sub, and run the code after my 'Remainder comment?

I seem to be getting inconsistent results from this is different
situations, but obvoiusly that is me not understanding how it works.

Hope that makes sense?

Alan.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Private Sub Workbook_Open:

' Does stuff

frmMainMenu.Show

' Remainder

End Sub


In userform:


Private Sub cmdAdministration_Click()

' Allows the admin user to exit from code control and access the
underlying spreadsheet

InputPassword = InputBox("This will allow you to make manual
adjustments directly to the database, add or change locations, types,
sales reps etc." & Chr(13) & Chr(13) & _
"You will be outside the control of the system, and substantial
damage could be caused to the database." & Chr(13) & Chr(13) & _
"If you are sure you want to continue, please enter the admin
password, else click cancel.", "Administration Password Required")

If InputPassword = Password Then

Application.CalculateFull

Application.Calculation = xlCalculationAutomatic

Unload Me

End If

End Sub
 
Alan,

That is how it should work.

If you put breaks in the code, you should see the course of events.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
works.

You could try using OnTime in the Workbook_Open to run a Sub Main
containing you 'Does stuff' etc code. I don't know if this would yield
more consistent results but at least you would have peace of mind that
the workbook is finishing opening before your code takes effect.
Jamie.

--
 
That's a very good point Jamie. I have had a few instances where code does
not seem to get executed, and adding Ontime to fir a routine that executed
that routine solved the problem. Had it with menubars, and with forms.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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


Back
Top