|
-
Jun 17th, 2004, 02:12 AM
#1
Thread Starter
Junior Member
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.
-
Jun 17th, 2004, 02:59 AM
#2
If you want to display the contents of one of the fields from yuour DB in a combo use the code below.
VB Code:
Do Until MyRecordset.EOF = True
Combo1.Additem MyRecordset!Myitem
MyRecordset.Movenext
Loop
-
Jun 17th, 2004, 03:00 AM
#3
VB Code:
A very simple way (it works for me) using a Data control with properties set as follows:
Recordset Type: Table
Database name: your Access file
Record source: the Table name
Public Sub FillCombo()
Dim i As Integer, k As Integer
i = Data1.Recordset.RecordCount
Data1.Recordset.MoveFirst
For k = 0 To i - 1
Combo1.AddItem Data1.Recordset.Fields("FieldName")
Data1.Recordset.MoveNext
Next
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)
-
Jun 17th, 2004, 03:01 AM
#4
Addicted Member
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:
On Error Resume Next
ObJr.MoveFirst
Do Until obJr.EOF
combo1.AddItem obJR.Fields("Field_Name")
ObJr.MoveNext
Loop
Objr.MoveFirst
-
Jun 17th, 2004, 11:36 PM
#5
Thread Starter
Junior Member
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!
-
Jun 18th, 2004, 02:58 AM
#6
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)
-
Jun 18th, 2004, 04:06 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|