Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default close UserForm

Received a runtime 91 error "Object variable or With block variable not
set" error when closing an user form. Excel debug go right to 'Load
UserForm1" statement. All code run smoothly up to this point.

Help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default close UserForm

Sounds like you have an error in your code where you try to use an object
that is not set to a reference. Probably in some code that fires when the
userform is closed.

for instances if you had

Private Sub Cmd_OK_Click()
rng.Value = Textbox1.Value
Unload me
End sub

if rng was not pointing to a range object, you would get such an error.

--
Regards,
Tom Ogilvy




" wrote:

Received a runtime 91 error "Object variable or With block variable not
set" error when closing an user form. Excel debug go right to 'Load
UserForm1" statement. All code run smoothly up to this point.

Help!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default close UserForm

Without seeing the code in the UserForm_Terminate event, it is difficult to
determine the cause of the problem. In order to have the editor take you to
the offending line of code, in VBA go to the Tools menu, choose Options,
then the "General" tab. There, select "Break In Class Module" instead of
"Break On Unhandled Errors".


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)

wrote in message
oups.com...
Received a runtime 91 error "Object variable or With block variable not
set" error when closing an user form. Excel debug go right to 'Load
UserForm1" statement. All code run smoothly up to this point.

Help!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default close UserForm

I'm having the same problem unloading a userform...thought until last night
that error 91 was caused by trying to show a highlighted default in the
listbox because without the line .ControlSource = "Sheet1!AA19" everything
worked fine. Last night I discovered the default and everything else worked
without the Unload Me command except that the userform won't unload (Duh!) I
tried Unload CropMonth, which is the name of the userform but I get the same
error. It's a userform with only a single selection listbox which I want to
default to the last selection when it initializes and close when the user
clicks a selection. Here's the code:

Private Sub ListBox1_Click()
Sheets("sheet1").Range("AA19").Value = ListBox1.Value
Unload Me '(everything works w/o this line except won't unload
form.)
End Sub

Private Sub UserForm_Initialize()
With ListBox1
.RowSource = ""
.AddItem "N/A"
.AddItem "January"
.AddItem "February"
.AddItem "March"
.AddItem "April"
.AddItem "May"
.AddItem "June"
.AddItem "July"
.AddItem "August"
.AddItem "September"
.AddItem "October"
.AddItem "November"
.AddItem "December"
.ControlSource = "sheet1!AA19" '(Everything works w/o this but no
default.)
End With
End Sub

I would also appreciate any help regarding this problem. Thanks, Katrina
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto close userform AOU Excel Discussion (Misc queries) 0 December 28th 06 06:54 PM
Close button userform Excelerate-nl Excel Programming 1 March 23rd 06 11:02 AM
Automatically close a userform ForSale[_53_] Excel Programming 1 October 2nd 04 12:47 AM
Close a userform Alvin Hansen[_2_] Excel Programming 1 September 26th 04 12:56 PM
Userform Close button Juan Excel Programming 5 May 6th 04 10:15 PM


All times are GMT +1. The time now is 07:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"