Results 1 to 7 of 7

Thread: how to link Combo Box to Access

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2004
    Location
    malaysia
    Posts
    29

    how to link Combo Box to Access

    hi, there
    i hav a combo box on a form, and the form is linked to Access. So, how do i link combo box to Access? Pls help...
    thx in advanced.

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    If you want to display the contents of one of the fields from yuour DB in a combo use the code below.

    VB Code:
    1. Do Until MyRecordset.EOF = True
    2. Combo1.Additem MyRecordset!Myitem
    3. MyRecordset.Movenext
    4. Loop

  3. #3
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    VB Code:
    1. A very simple way (it works for me) using a Data control with properties set as follows:
    2. Recordset Type: Table
    3. Database name: your Access file
    4. Record source: the Table name
    5. Public Sub FillCombo()
    6.     Dim i As Integer, k As Integer
    7.     i = Data1.Recordset.RecordCount
    8.     Data1.Recordset.MoveFirst
    9.     For k = 0 To i - 1
    10.         Combo1.AddItem Data1.Recordset.Fields("FieldName")
    11.         Data1.Recordset.MoveNext
    12.     Next
    13. End Sub
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    Hi, the best way i find, is in the form load put this code
    obviously source and open your adodb connection
    chage obJR to your connection

    VB Code:
    1. On Error Resume Next
    2.     ObJr.MoveFirst
    3.     Do Until obJr.EOF
    4.     combo1.AddItem obJR.Fields("Field_Name")
    5.     ObJr.MoveNext
    6.     Loop
    7.  
    8. Objr.MoveFirst

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2004
    Location
    malaysia
    Posts
    29
    hi, there
    thx for your helps and the code! i am newbie to VB, so i don't really understand some of the posted VB code.

    k0r54 and lintz
    hee... if posible, can you pls explain to me the code? thx

    krtxmrtz
    i am using Data Control too, but where to put the code under Data1_Validate?

    actually, i want to use combination of combo box with text box, where GotFocus() and SetFocus() are used.Sth like this. i am not very sure. is it possible? pls show me...
    thx in advanced!

  6. #6
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    krtxmrtz
    i am using Data Control too, but where to put the code under Data1_Validate?[/B]
    My code above just fills a combo with all the records from a specific field.
    What kind of validation do you mean?

    actually, i want to use combination of combo box with text box, where GotFocus() and SetFocus() are used.Sth like this. i am not very sure. is it possible? pls show me...
    thx in advanced!
    Could you explain better how you want to use this combination of combo + textbox?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  7. #7
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    My code fills a combo box from a specified field within your database.

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