VB Run Time Error 3265 "item not found in this collection"

jimwaite
jimwaite used Ask the Experts™
on
Hello people.

I am receiving the VB  run time error 3265 "item not found in this collection"

This is my code: can't see anything unusual:

--------------------------------------------------------------------------------------------------

    Dim CarMake As String
    Dim CarModel As String
    Dim CarMileage As Long
    Dim CarEngine As Long
    Dim CarChassis As Long
    Dim CarColour As String
    Dim CarNoServices As Integer
    Dim CarServiceRefs(5) As Integer
       
    CarMake = Form1.Text1.Text
    CarModel = Form1.Text2.Text
    CarMileage = Form1.Text3.Text
    CarEngine = Form1.Text4.Text
    CarChassis = Form1.Text5.Text
    CarColour = Form1.Text6.Text
    CarNoServices = Form1.Text7.Text
    CarServiceRefs(1) = Form1.Text8.Text
    CarServiceRefs(2) = Form1.Text9.Text
    CarServiceRefs(3) = Form1.Text10.Text
    CarServiceRefs(4) = Form1.Text11.Text
    CarServiceRefs(5) = Form1.Text12.Text
   
    dclExample.Recordset.AddNew
    dclExample.Recordset!Make = CarMake
    dclExample.Recordset!Model = CarModel
    dclExample.Recordset!Mileage = CarMileage
    dclExample.Recordset!EngineSize = CarEngine
    dclExample.Recordset!ChassisNumber = CarChassis
    dclExample.Recordset!Colour = CarColour
    dclExample.Recordset!NumberOfServices = CarNoServices
    dclExample.Recordset!ServiceReferenceNumber(1) = CarServiceRefs(1)
    dclExample.Recordset!ServiceReferenceNumber(2) = CarServiceRefs(2)
    dclExample.Recordset!ServiceReferenceNumber(3) = CarServiceRefs(3)
    dclExample.Recordset!ServiceReferenceNumber(4) = CarServiceRefs(4)
    dclExample.Recordset!ServiceReferenceNumber(5) = CarServiceRefs(5)

--------------------------------------------------------------------------------------------------

Any ideas?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dim CarServiceRefs(5) As Integer
This will give you array elements 0-4 unless you have changed the default array boundry of 0
This is not good syntax:

    dclExample.Recordset!ServiceReferenceNumber(1) = CarServiceRefs(1)
    dclExample.Recordset!ServiceReferenceNumber(2) = CarServiceRefs(2)
    dclExample.Recordset!ServiceReferenceNumber(3) = CarServiceRefs(3)
    dclExample.Recordset!ServiceReferenceNumber(4) = CarServiceRefs(4)
    dclExample.Recordset!ServiceReferenceNumber(5) = CarServiceRefs(5)

My guess is it's choking on the parentheses.  The ! operator on the recordset is really a shorthand for saying...

    dclExample.Recordset.Fields("ServiceReferenceNumber(1)").Value
    'etc.

This would only be valid if there were actually a field named ServiceReferenceNumber(1), including the parentheses.  I'm guessing there isn't actually a field named ServiceReferenceNumber(1).

What is the actual field name?  (Or am I wrong?)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial