ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Flow of control in VBA Question - Userform Interaction (https://www.excelbanter.com/excel-programming/319481-flow-control-vba-question-userform-interaction.html)

Alan

Flow of control in VBA Question - Userform Interaction
 
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






Bob Phillips[_6_]

Flow of control in VBA Question - Userform Interaction
 
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)


"Alan" wrote in message
...
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








onedaywhen[_2_]

Flow of control in VBA Question - Userform Interaction
 
Alan wrote:
I seem to be getting inconsistent results from this is different
situations, but obvoiusly that is me not understanding how it

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.

--


Bob Phillips[_6_]

Flow of control in VBA Question - Userform Interaction
 
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)


"onedaywhen" wrote in message
oups.com...
Alan wrote:
I seem to be getting inconsistent results from this is different
situations, but obvoiusly that is me not understanding how it

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.

--





All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com