PDA

View Full Version : [SOLVED:] populating combobox from access table



WILDDUSTIE
04-09-2017, 06:10 PM
I am relatively new to programming and have an issue I can't seem to overcome. I'm creating a user form and two comboboxes are required. I need them to populate by reading from two separate access tables. Here is what I have so far:



Private Sub UserForm_Initialize()


Dim dbConnection As Object
Dim recordSet As Object
Dim strSQL As String
Dim strConnectionConfig As String


Set dbConnection = CreateObject("ADODB.Connection")


strConnectionConfig = "Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source = ASSIGNMENT 4.accdb;"


dbConnection.Open (strConnectionConfig)


strSQL = "SELECT DISTINCT DOCTORID FROM DOCTOR"


Set recordSet = dbConnection.Execute(strSQL)


SETAPPTUF.DRIDCB.AddItem ("ALL")


Do While (Not recordSet.EOF)
SETAPPTUF.DRIDCB.AddItem (recordSet("DOCTORID"))

recordSet.MoveNext
Loop


strSQL = "SELECT DISTINCT PATIENTID FROM PATIENT"


Set recordSet = dbConnection.Execute(strSQL)


SETAPPTUF.PTIDCB.AddItem ("ALL")


Do While (Not recordSet.EOF)
SETAPPTUF.PTIDCB.AddItem (recordSet("PATIENTID"))
recordSet.MoveNext
Loop




End Sub


Any help is appreciated.

snb
04-10-2017, 12:19 AM
Please use code tags.

This is all you need:

Sub Access_query_combobox_snb()
With CreateObject("ADODB.Connection")
.Open "SELECT * FROM Q_test", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Access\fiets.mdb"
ComboBox1.Column = .GetRows
End With
End Sub

WILDDUSTIE
04-10-2017, 03:44 AM
Using this suggestion still did not put the required lists into the two boxes, but I did get help on another. Thanks for responding.


Please use code tags.

This is all you need:

Sub Access_query_combobox_snb()
With CreateObject("ADODB.Connection")
.Open "SELECT * FROM Q_test", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Access\fiets.mdb"
ComboBox1.Column = .GetRows
End With
End Sub

snb
04-10-2017, 03:51 AM
If you are crossposting: that's not being appreciated !

And: do not Quote !

WILDDUSTIE
04-10-2017, 05:01 AM
Again...relatively new. Not sure what you mean by "crossposting"? From context, it seems you are saying that once I ask for help it is somehow impolite to keep looking for my own answer through other resources? That seems kind of ridiculous, but if that is a generally accepted attitude then I may have to reconsider asking for help. I was under the impression that these forums were to help each other. I'm sorry if I was mistaken. Thanks for letting me know that self-help is not "appreciated".

mancubus
04-10-2017, 05:43 AM
http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3
crossposting from FAQ...


http://www.excelguru.ca/content.php?184


this is what snb meant when you said "i did get help..."

mancubus
04-10-2017, 05:44 AM
.......