Bring Data From MS Acess in a Combobox

G

gatarossi

Dear all,

I have this code that brings the MS Access data in a cell... but I
need that excel brings these data in a combobox (when I initialize a
userform)...

This is the code:

Sub return_approval()

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset

Set db = OpenDatabase(ThisWorkbook.Path & "\db_sales_pgm.mdb", False,
False, "MS Access;PWD=salespgm")
Set qdf = db.QueryDefs("qry_approval")
Set rs = qdf.OpenRecordset(dbOpenForwardOnly)

With ActiveSheet
.Cells(1, 1).CopyFromRecordset rs
End With

Set db = Nothing
Set qdf = Nothing
Set rs = Nothing

End Sub


This is the MS Access Query:

SELECT DISTINCT tbl_approval.doct_n
FROM tbl_approval;

My userform name's is frmQuery and the combobox name is cboApproval

Thanks in advance!!!

André.
 
H

Harald Staff

Hi Andre

Not sure about DAO, with ADO it's like this

Do Until rs.EOF
frmQuery.cboApproval.Additem rs(0)
rs.MoveNext
Loop

HTH. Best wishes Harald

Dear all,

I have this code that brings the MS Access data in a cell... but I
need that excel brings these data in a combobox (when I initialize a
userform)...

This is the code:

Sub return_approval()

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset

Set db = OpenDatabase(ThisWorkbook.Path & "\db_sales_pgm.mdb", False,
False, "MS Access;PWD=salespgm")
Set qdf = db.QueryDefs("qry_approval")
Set rs = qdf.OpenRecordset(dbOpenForwardOnly)

With ActiveSheet
.Cells(1, 1).CopyFromRecordset rs
End With

Set db = Nothing
Set qdf = Nothing
Set rs = Nothing

End Sub


This is the MS Access Query:

SELECT DISTINCT tbl_approval.doct_n
FROM tbl_approval;

My userform name's is frmQuery and the combobox name is cboApproval

Thanks in advance!!!

André.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top