Home All Groups Group Topic Archive Search About

Subscript out of range VB 6 on loading a form

Author
24 Mar 2009 1:07 PM
david
Below is the code that runs when I try to open a form.

The message occurs as soon as a control is set on the form. ie if I
rem out the line  frm.lblID.Caption = "" the error occurs on the line
frm.cbPO = myID

This is strange because it has only just started to happen with out a
code change.

Any ideas greatly appreciated

thanks

Public Sub Show(ByRef cn As ADODB.Connection, ByRef parent As Object)

    Dim frm As New FrmGoodsIn
    Set frm.parent = parent
    frm.lblID.Caption = ""
----- Error message comes here --------Runtime error 9 - Subscript out
of range
    Set frm.cn = cn
    PopulateCombos frm, cn
    frm.cbPO = myID
    frm.txtSupplierAccountRef.Text = GetSupplierRef(myID, cn)
    frm.cbPO.Enabled = False
    frm.CreateGRNItems
    frm.PopulateGRNItems
    frm.Show

End Sub

Author
24 Mar 2009 1:18 PM
Nobody
<da***@thechameleongroup.co.uk> wrote in message
Show quoteHide quote
news:52c00c9b-85ed-48e5-a19f-0c5a4f424f76@j38g2000yqa.googlegroups.com...
> Below is the code that runs when I try to open a form.
>
> The message occurs as soon as a control is set on the form. ie if I
> rem out the line  frm.lblID.Caption = "" the error occurs on the line
> frm.cbPO = myID
>
> This is strange because it has only just started to happen with out a
> code change.
>
> Any ideas greatly appreciated
>
> thanks
>
> Public Sub Show(ByRef cn As ADODB.Connection, ByRef parent As Object)
>
>    Dim frm As New FrmGoodsIn
>    Set frm.parent = parent
>    frm.lblID.Caption = ""
> ----- Error message comes here --------Runtime error 9 - Subscript out
> of range
>    Set frm.cn = cn
>    PopulateCombos frm, cn
>    frm.cbPO = myID
>    frm.txtSupplierAccountRef.Text = GetSupplierRef(myID, cn)
>    frm.cbPO.Enabled = False
>    frm.CreateGRNItems
>    frm.PopulateGRNItems
>    frm.Show
>
> End Sub

What's the Index property for lblID and cbPO set to in FrmGoodsIn?

How myID was declared?
Are all your drivers up to date? click for free checkup

Author
24 Mar 2009 1:29 PM
david
Thanks for quick repsonse

Index property for lblID not set and is blank and so is cbPO


Option Explicit

Dim m_myID As Long

Public Property Let myID(newID As Long)
    m_myID = newID
End Property

Public Property Get myID() As Long
    myID = m_myID
End Property
Author
24 Mar 2009 4:00 PM
Larry Serflaten
<da***@thechameleongroup.co.uk> wrote


> This is strange because it has only just started to happen with out a
> code change.
>
> Any ideas greatly appreciated

These two lines don't sit well with me:

>     frm.cbPO = myID
>     frm.cbPO.Enabled = False

The first line treats cbPO like a variable and the second like an object.
If you mean:   frm.sbPO.Text = myID    then use that....

See if it makes a difference ???

LFS
Author
25 Mar 2009 3:34 AM
Ian King
da***@thechameleongroup.co.uk wrote in news:52c00c9b-85ed-48e5-a19f-
0c5a4f424***@j38g2000yqa.googlegroups.com:

Show quoteHide quote
> Below is the code that runs when I try to open a form.
>
> The message occurs as soon as a control is set on the form. ie if I
> rem out the line  frm.lblID.Caption = "" the error occurs on the line
> frm.cbPO = myID
>
> This is strange because it has only just started to happen with out a
> code change.
>
> Any ideas greatly appreciated
>
> thanks
>
> Public Sub Show(ByRef cn As ADODB.Connection, ByRef parent As Object)
>
>     Dim frm As New FrmGoodsIn
>     Set frm.parent = parent
>     frm.lblID.Caption = ""
> ----- Error message comes here --------Runtime error 9 - Subscript out
> of range
>     Set frm.cn = cn
>     PopulateCombos frm, cn
>     frm.cbPO = myID
>     frm.txtSupplierAccountRef.Text = GetSupplierRef(myID, cn)
>     frm.cbPO.Enabled = False
>     frm.CreateGRNItems
>     frm.PopulateGRNItems
>     frm.Show
>
> End Sub
>

"Break on all errors" might help (Tools/Options/General).

Most likely the error occurs in the Form_Load event of FrmGoodsIn form.
Probably because you are accessing an array that hasn't yet been
dimensioned, or something like that.

Ian
Author
25 Mar 2009 9:04 AM
david
Thanks for the repsonase but no luck i am afraid
I changed the variable code to .text and tried the break on all errors
but the results were the same.

I put a break in the form load proceedure it runs it after the Runtime
Error 9 subscript out of range message which occurs at the lines that
involve setting values to controls on the form. I agree it is like the
array of controls has not been built yet and thus cant access it. The
strange thing is that it has only just started to happen without a
code change which tells me its more likely to do with a registration
of the dll or PC reason or somethign like that.

The quest continues.....:-)

thanks

Bookmark and Share