Results 1 to 3 of 3

Thread: simple one

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Unhappy

    in the 3+ years I have been doing vb, I still have problems with the loop functions. Below I am trying to add an access97 database column's entries into a ComboBox on an excel form...

    Code:
    Private Sub Workbook_Open()
    
    Dim db As Database
    Dim rs As Recordset
    Dim cmb As Object
    Dim i As Integer, x As Integer
    Dim txt As Variant
        Set db = OpenDatabase("C:\A_Database.mdb")
        Set rs = db.OpenRecordset("A_Table")
        Set cmb = Worksheets(1).ComboBox1
        txt = rs.Fields(x).Value
        x = 1
    
        For i = 0 To rs.Fields.Count
            cmb.AddItem txt
            x = x + 1
        Next i
    
    End Sub
    HHEEELLLLLLPPPPP please, I guess this is a simple one anyway & think most people here must have encountered this at one stage or another, am I slightly out in my coding, or off the planet?

    Thank you everyone!
    Alex Read

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Member
    Join Date
    Nov 1999
    Location
    panama
    Posts
    57
    try this:

    using datacontrol

    Data1.DatabaseName = App.Path & "\person.mdb"
    Data1.RecordSource = "educacion"
    Data1.Refresh
    Data1.Recordset.MoveLast
    cant1 = Data1.Recordset.RecordCount
    Data1.Recordset.MoveFirst
    For i = 1 To cant1
    Combo3.AddItem Data1.Recordset.Fields("educacion")
    Data1.Recordset.MoveNext
    Next i
    Combo3.ListIndex = 0
    carlosapv
    [email protected]
    THE TRUTH IS OUT THERE
    Visual Basic 6.0 SP5

  3. #3

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Talking Cheers Carlos !!!!!!

    Realised I should have used the rs.movenext (I should know that one).
    I was calling this from Excel, so did not use the data control.

    This helped anyway & all is working!
    Thank you once again!
    Alex

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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