run-time error '340' Control array element '8' doesn't exist 
Author Message
 run-time error '340' Control array element '8' doesn't exist

Hi,

I am using the following code to save a report before printing.  I have 8
data controls one "Data1" and other 7 "datTabs" starting with index 0.
Initially I wrote this code in vb 5 and works perfect, after upgrading to vb
6 and access 2000, I get "run-time error '340' Control array element '8'
doesn't exist"  I have changed all my recordset and database to
ado.recordset and ado.database which I can use the form and search data with
no problem.

Please help if I need to change some of this code to make it work with VB 6.

Thanks!

Private Sub mnuFileSaveReport_Click()
Dim iTabs As Integer
Dim strError As String

On Error GoTo ErrorX

    If bReadyToPrint Then
        strError = "Data1"
        frmREntry.Data1.Recordset.Edit
        frmREntry.Data1.Recordset.Update

        strError = "datTabs"
        For iTabs = 0 To frmREntry.datTabs.Count
            If frmREntry.datTabs(iTabs).Recordset.RecordCount > 0 Then
                frmREntry.datTabs(iTabs).Recordset.Edit
                frmREntry.datTabs(iTabs).Recordset.Update
            End If
        Next iTabs

        'strError = "dbREntry"
        'For i = 0 To dbREntry.Recordsets.Count - 1
          '  dbREntry.Recordsets(i).Edit
           ' dbREntry.Recordsets(i).Update
        'Next i
    Else
        MsgBox "You must open a report to save it!"
        Exit Sub
    End If

Exit Sub
ErrorX:
    MsgBox "Error saving report. " & Err.Description
    MakeErrorLog "mnuFileSaveReport", strError, Err.Description, Err.Number
    Exit Sub

End Sub



Sat, 03 Dec 2005 01:25:17 GMT  
 run-time error '340' Control array element '8' doesn't exist
Sorry I meant to say DAO not ADO on my Message.

BJ


Quote:
> Hi,

> I am using the following code to save a report before printing.  I have 8
> data controls one "Data1" and other 7 "datTabs" starting with index 0.
> Initially I wrote this code in vb 5 and works perfect, after upgrading to
vb
> 6 and access 2000, I get "run-time error '340' Control array element '8'
> doesn't exist"  I have changed all my recordset and database to
> ado.recordset and ado.database which I can use the form and search data
with
> no problem.

> Please help if I need to change some of this code to make it work with VB
6.

> Thanks!

> Private Sub mnuFileSaveReport_Click()
> Dim iTabs As Integer
> Dim strError As String

> On Error GoTo ErrorX

>     If bReadyToPrint Then
>         strError = "Data1"
>         frmREntry.Data1.Recordset.Edit
>         frmREntry.Data1.Recordset.Update

>         strError = "datTabs"
>         For iTabs = 0 To frmREntry.datTabs.Count
>             If frmREntry.datTabs(iTabs).Recordset.RecordCount > 0 Then
>                 frmREntry.datTabs(iTabs).Recordset.Edit
>                 frmREntry.datTabs(iTabs).Recordset.Update
>             End If
>         Next iTabs

>         'strError = "dbREntry"
>         'For i = 0 To dbREntry.Recordsets.Count - 1
>           '  dbREntry.Recordsets(i).Edit
>            ' dbREntry.Recordsets(i).Update
>         'Next i
>     Else
>         MsgBox "You must open a report to save it!"
>         Exit Sub
>     End If

> Exit Sub
> ErrorX:
>     MsgBox "Error saving report. " & Err.Description
>     MakeErrorLog "mnuFileSaveReport", strError, Err.Description,
Err.Number
>     Exit Sub

> End Sub



Sat, 03 Dec 2005 01:56:48 GMT  
 run-time error '340' Control array element '8' doesn't exist
Here you loop from 0 to Tabs.Count but you should stop at
(Tabs.Count)-1 because going from 0 to 8 will result in referencing
the ninth tab at the last step (0,1,2,3,4,5,6,7,8) while you only have
eight of them.
For iTabs = 0 To (frmREntry.datTabs.Count - 1)
Also, you may also check Option Base Statement which also affects
array indexing.
Your commented code looked correct, by the way.

Hope this helps,

Max Kudrenko
Brainbench MVP Program for Visual Basic
www.brainbench.com

Quote:

> Hi,
> I am using the following code to save a report before printing.  I have 8
> data controls one "Data1" and other 7 "datTabs" starting with index 0.
> Initially I wrote this code in vb 5 and works perfect, after upgrading to vb
> 6 and access 2000, I get "run-time error '340' Control array element '8'
> doesn't exist"  I have changed all my recordset and database to
> ado.recordset and ado.database which I can use the form and search data with
> no problem.
> Please help if I need to change some of this code to make it work with VB 6.
> Thanks!

> Private Sub mnuFileSaveReport_Click()

>         For iTabs = 0 To frmREntry.datTabs.Count

>         Next iTabs



Sat, 03 Dec 2005 22:25:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Run-time error 340 - Control array element '4' doesn't exist

2. Control Array Element '0' Doesn't Exist (Error 340)

3. Control array element doesn't exist error

4. Run time error 340 - control array element does not exist

5. Run time error '35605': This item's control has been deleted

6. Run-time error '462': The remote server machine does not exist or is unavailable

7. Error 340: Control array element doesn't exist! Why?

8. Table's Field doesn't bind to HTML Control Element

9. Table's Field doesn't bind to HTML Control Element

10. Table's Field doesn't bind to HTML Control Element

11. Error 340: Control array element doesn't exist! Why?

12. Run-time error '429': ActiveX component can't create object

 

 
Powered by phpBB® Forum Software