Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Run-time error '9'

I encountered "Run-time error '9': Subscript out of range" at this line:

Form_MyForm.Show

The form is sitting there and no spelling error. Anyone can help?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 320
Default Run-time error '9'

Something inside the initialize event is causing the error. Put a breakpoint
in the initialize code and step through to see where it fails.
Bob Umlas
Excel MVP

"Scott" wrote in message
...
I encountered "Run-time error '9': Subscript out of range" at this line:

Form_MyForm.Show

The form is sitting there and no spelling error. Anyone can help?

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Run-time error '9'

Hey Scott -

Is the name of your form "Form_MyForm" ? That is the syntax I use to pull
up my forms - so I would assume that it relates to something you put on the
form. Did you load data onto your form prior to calling Form_MyForm.Show?

"Scott" wrote:

I encountered "Run-time error '9': Subscript out of range" at this line:

Form_MyForm.Show

The form is sitting there and no spelling error. Anyone can help?

Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Run-time error '9'

Is the name Form_MyForm or just MyForm? In the later case, you should use
MyForm.Show. I would also use MyForm.Show (vbModeless) or MyForm.Show
(vbModal), depending on what you want the form to do.

Dan

"Scott" wrote:

I encountered "Run-time error '9': Subscript out of range" at this line:

Form_MyForm.Show

The form is sitting there and no spelling error. Anyone can help?

Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Run-time error '9'

Thank you all for the replies.

Here are the codes:
Private Sub CommandButton1_Click()
Form_Main.Hide
Form_MyForm1.Show
End Sub

The program worked fine yesterday. I made some changes today and I cannot
remember every step I did. Suddently, I got into this trouble. Strangely,
when I added a new form "UserForm1" and replaced the "Form_MyForm1.Show" with
"UserForm1.Show" above, it just worked.

I guess I probably broke a link with "Form_MyForm1.Show", but have no clue
how I did and what to do to correct it.



"Scott" wrote:

I encountered "Run-time error '9': Subscript out of range" at this line:

Form_MyForm.Show

The form is sitting there and no spelling error. Anyone can help?

Thanks.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Run-time error '9'

By default, error trapping is set at "break unhandled errors". A side
effect of this is that any error that occurs in an object module
(e.g., a class module or userform) will cause the code to stop and
enter debug mode on the line of code that created an instance of an
object.

In your code, there is really nothing wrong with the code
Form_MyForm.Show, and you could spend all day trying to figure out
what is wrong. However, this is the code that instantiates the form
to an object. Any error in the form will cause a break on this line of
code.

In VBA, go to the Tools menu, choose Options, then the General tab.
There, ensure that "Break In Class Module" is selected. When this
option is in effect, the compiler will break on the actual line of
code that is causing the problem. You should ALWAYS have Break In
Class Module in effect. I can't think of any good reason that you
would want it otherwise.

An error 9 -- subscript out of range -- typically occurs when you
attempt to retrieve an item from a collection and that item doesn't
exist. For example, if you have no worksheet named "DoesNotExist", the
code Set WS = Worksheets("DoesNotExist") will throw an error 9 because
there is no such sheet in the Worksheets collection.


Cordially,
Chip Pearson
Microsoft MVP
Excel 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]


On Wed, 18 Nov 2009 13:01:01 -0800, Scott
wrote:

I encountered "Run-time error '9': Subscript out of range" at this line:

Form_MyForm.Show

The form is sitting there and no spelling error. Anyone can help?

Thanks.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Run-time error '9'

Problem solved. Thank you very much.


"Chip Pearson" wrote:

By default, error trapping is set at "break unhandled errors". A side
effect of this is that any error that occurs in an object module
(e.g., a class module or userform) will cause the code to stop and
enter debug mode on the line of code that created an instance of an
object.

In your code, there is really nothing wrong with the code
Form_MyForm.Show, and you could spend all day trying to figure out
what is wrong. However, this is the code that instantiates the form
to an object. Any error in the form will cause a break on this line of
code.

In VBA, go to the Tools menu, choose Options, then the General tab.
There, ensure that "Break In Class Module" is selected. When this
option is in effect, the compiler will break on the actual line of
code that is causing the problem. You should ALWAYS have Break In
Class Module in effect. I can't think of any good reason that you
would want it otherwise.

An error 9 -- subscript out of range -- typically occurs when you
attempt to retrieve an item from a collection and that item doesn't
exist. For example, if you have no worksheet named "DoesNotExist", the
code Set WS = Worksheets("DoesNotExist") will throw an error 9 because
there is no such sheet in the Worksheets collection.


Cordially,
Chip Pearson
Microsoft MVP
Excel 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]


On Wed, 18 Nov 2009 13:01:01 -0800, Scott
wrote:

I encountered "Run-time error '9': Subscript out of range" at this line:

Form_MyForm.Show

The form is sitting there and no spelling error. Anyone can help?

Thanks.

.

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
run time error 1004 general odbc error excel 2003 vba Mentos Excel Programming 5 January 24th 11 02:56 PM
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Error handling error # 1004 Run-time error [email protected] Excel Programming 3 May 20th 08 02:23 PM
Run Time Error 1004: Application or Object Defined Error BEEJAY Excel Programming 4 October 18th 06 04:19 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


All times are GMT +1. The time now is 09:01 PM.

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

About Us

"It's about Microsoft Excel"