ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting error unloading Userform?? (https://www.excelbanter.com/excel-programming/333344-getting-error-unloading-userform.html)

Ed

Getting error unloading Userform??
 
In a certain workbook, code in the ThisWorkbook module creates a new menu
with one item when the workbook opens. The one item calls a macro in a
general module in the workbook. The macro has one item:
Load UserForm1

The Form_Initialize code gets the name of every sheet in the workbook and
populates a ComboBox control. The form has an "Exit" CommandButton, with
two lines of code:
Set wb = Nothing
Unload Me

When I click the Exit button, the form unloads and disappears, but the code
then errors with 91: Object variable or With variable not set. The VBE
opens with the
Load UserForm1
line in the original macro highlighted in yellow.

How should I fix this?

Ed



Jim Cone

Getting error unloading Userform??
 
Ed,

Not quite sure what is calling whom when, but I believe
you should...
1. change the code for the exit button from
Unload Me to Me.Hide
2. and then...
add the line "Unload UserForm1" following the
"UserForm1.Show" line, where ever that is.

Regards,
Jim Cone
San Francisco, USA

"Ed" wrote in message
...
In a certain workbook, code in the ThisWorkbook module creates a new menu
with one item when the workbook opens. The one item calls a macro in a
general module in the workbook. The macro has one item:
Load UserForm1

The Form_Initialize code gets the name of every sheet in the workbook and
populates a ComboBox control. The form has an "Exit" CommandButton, with
two lines of code:
Set wb = Nothing
Unload Me

When I click the Exit button, the form unloads and disappears, but the code
then errors with 91: Object variable or With variable not set. The VBE
opens with the
Load UserForm1
line in the original macro highlighted in yellow.

How should I fix this?

Ed



Ed

Getting error unloading Userform??
 
UserForm1.Show is in the Initialize code, right after the ComboBox loop
ends. If I put it there, wouldn't it unload the form right after showing
it?

Ed

"Jim Cone" wrote in message
...
Ed,

Not quite sure what is calling whom when, but I believe
you should...
1. change the code for the exit button from
Unload Me to Me.Hide
2. and then...
add the line "Unload UserForm1" following the
"UserForm1.Show" line, where ever that is.

Regards,
Jim Cone
San Francisco, USA

"Ed" wrote in message
...
In a certain workbook, code in the ThisWorkbook module creates a new menu
with one item when the workbook opens. The one item calls a macro in a
general module in the workbook. The macro has one item:
Load UserForm1

The Form_Initialize code gets the name of every sheet in the workbook and
populates a ComboBox control. The form has an "Exit" CommandButton, with
two lines of code:
Set wb = Nothing
Unload Me

When I click the Exit button, the form unloads and disappears, but the

code
then errors with 91: Object variable or With variable not set. The VBE
opens with the
Load UserForm1
line in the original macro highlighted in yellow.

How should I fix this?

Ed





Jim Cone

Getting error unloading Userform??
 
Ed,

No it won't. The normal sequence is...

'------------------
Sub Demo
'code here to check stuff

UserForm1.Show
'do stuff while form is shown - click option buttons etc.
'then hide the form by clicking a button on the form (Me.Hide)

'code here to check for any settings on the form, for instance
'an entry in a textbox or which option button was clicked.

Unload UserForm1 '(Me can't be used)
'additional code here
Set UserForm1 = Nothing
End Sub
'-------------------
Jim Cone
San Francisco, USA



"Ed" wrote in message
...
UserForm1.Show is in the Initialize code, right after the ComboBox loop
ends. If I put it there, wouldn't it unload the form right after showing
it?
Ed

"Jim Cone" wrote in message
...
Ed,

Not quite sure what is calling whom when, but I believe
you should...
1. change the code for the exit button from
Unload Me to Me.Hide
2. and then...
add the line "Unload UserForm1" following the
"UserForm1.Show" line, where ever that is.

Regards,
Jim Cone
San Francisco, USA



"Ed" wrote in message
...
In a certain workbook, code in the ThisWorkbook module creates a new menu
with one item when the workbook opens. The one item calls a macro in a
general module in the workbook. The macro has one item:
Load UserForm1

The Form_Initialize code gets the name of every sheet in the workbook and
populates a ComboBox control. The form has an "Exit" CommandButton, with
two lines of code:
Set wb = Nothing
Unload Me
When I click the Exit button, the form unloads and disappears, but the

code then errors with 91: Object variable or With variable not set. The VBE
opens with the Load UserForm1
line in the original macro highlighted in yellow.
How should I fix this?
Ed





All times are GMT +1. The time now is 12:07 PM.

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