Results 1 to 3 of 3

Thread: [RESOLVED] VB6 .AddNew Record Problem involving Listbox Itemdata

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    12

    Resolved [RESOLVED] VB6 .AddNew Record Problem involving Listbox Itemdata

    VB6, MS Access 2000

    Hi! Would you please help me with the following problem?

    Let's just say there's no problem with connecting the database form,
    I'm trying to add new records using data from a listbox that is not 'placed' on top at the moment.

    Destination table
    Name: History
    Fields: EventID and StudentID

    Listbox on frmParticipants: lstParticipants, lstTIC

    I want to 'keep adding' new records on to the database, each record consists of the same EventID (from the currently '___.Show 1'-ed form) but different StudentID, depending on what's stored in the itemdata part of the list.
    E.g. What I should be seeing in the database:
    EventID StudentID
    12345 23456
    12345 34567
    12345 45678
    54321 33546
    .
    .
    .
    etc.
    Here's the code:

    Code:
       mrsHistory.Open "History", gcnCDC, adOpenStatic, adLockOptimistic, adCmdTable
       mrsHistory.AddNew
       With mrsHistory
          For Counter = 0 To frmParticipants.lstParticipants.ListCount - 1
             !EventID = Val(txtEventID)
             !StudentID = frmParticipants.lstStudents.ItemData(Counter)        '(frmParticipants.lstStudents.List(Counter))
          Next
       End With
    When I ran this, the following error is displayed:
    Error code: 381
    Description: Invalid property array index
    Source: _________ (<---database name)


    Any help would be appreciated!

    Thank you very much!

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: VB6 .AddNew Record Problem involving Listbox Itemdata

    1.- I would use a Dynamic cursor instead : adOpenDynamic

    2.- Try moving the add method inside the loop
    Code:
    'not a valid code...just to show the explanation
    For
        recordset.AddNew
          recordset!Field1 = value1
          recordset!Field2 = value2
        recordset.Update
    Next
    Last edited by jggtz; Apr 10th, 2013 at 09:55 AM.
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    12

    Re: VB6 .AddNew Record Problem involving Listbox Itemdata

    Thank you very much for your help, again! :P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width