Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2007
    Posts
    6

    Unanswered: Looping combo box in Subform

    Hi all,


    Wondering if there is a way that I can do this without a listbox.

    I have records in a subform and when I hit the command button it will update a linking table. I am trying to make it loop but the code below updates the first record but doesn't go down to the next record. Is there a why I can do this? Thanks in advance

    Code:
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset
        Dim qd As DAO.QueryDef
        
        Set dbs = CurrentDb
        Set qd = dbs.QueryDefs!qStudent
        Set rst = qd.OpenRecordset
    rst.MoveFirst
        Do Until rst.EOF
    
            rst.AddNew
            rst!MailingListID = Me.cboStudentID
            rst!Date = Me.txtDate
            rst!Type = Me.cboType
            rst!SponserID = Me.SponderID
            rst.Update
        rst.MoveNext
        
    Loop

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Uh ... Look CAREFULLY at your do loop ... WHAT IS the value of EOF when you're on a record????? <HINT>: Not True ...
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Feb 2007
    Posts
    6
    Not quite working because, when I have an empty table I get a run-time error 3021, no current record.

    If I add the last record in table into the query and run, it goes through and adds the first record. Then I see it loop and come back to to the first record and get a 3022 duplication error.

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Well I guess that you have some logic work to do then ... HINT: DAO puts you on the 1st record in a recordset by default ...
    Back to Access ... ADO is not the way to go for speed ...

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    And your other issue: The duplication, is because you're not iterating thru the records in your subform ... Is this form bound to the table you wish to write to?
    Back to Access ... ADO is not the way to go for speed ...

  6. #6
    Join Date
    Feb 2007
    Posts
    6
    No, it isn't bound to the table i am trying to write to.

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    We'll add another hint...

    consider looping through your combo box instead of looping through the recordset.

    From the looks of things you might be doing this the hard way to begin with. Hard to say without knowing more about your project.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  8. #8
    Join Date
    Feb 2007
    Posts
    6
    I don't want to loop through the combobox after thinking. I have a continous subform and the next number that it should loop to is 9. THis is a bound subform that is getting information from one table and adding it to another table.

Posting Permissions

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