G
gatarossi
Dear all,
I'm trying to bring some data from access and put it in a form (in
this case in a combobox). I realy don't know how to do it... I'm
trying to do it with the code below:
Public Sub getCn(ByRef dbcon As ADODB.Connection, ByRef dbrs As
ADODB.Recordset, _
sqlstr As String, dbfile As String, usernm As String, pword As String)
Set dbcon = New ADODB.Connection
dbcon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfile &
";", _
usernm, pword
Set dbrs = New ADODB.Recordset
dbrs.Open sqlstr, dbcon
End Sub
Sub return_customer()
Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
filenm = ThisWorkbook.Path & "\db.mdb"
sql = "SELECT DISTINCT buyer_name FROM table1 ORDER BY buyer_name ;"
Call getCn(adoconn, adors, sql, filenm, "", "")
cboCustomer.CopyFromRecordset adors
adors.Close
adoconn.Close
Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing
End Sub
After it, I would like to open the form, choose a customer in this
combobox, and the name of the customer selected will appear in a cell
of excel...
How can I do it???
Thanks in advance!!!
André.
I'm trying to bring some data from access and put it in a form (in
this case in a combobox). I realy don't know how to do it... I'm
trying to do it with the code below:
Public Sub getCn(ByRef dbcon As ADODB.Connection, ByRef dbrs As
ADODB.Recordset, _
sqlstr As String, dbfile As String, usernm As String, pword As String)
Set dbcon = New ADODB.Connection
dbcon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfile &
";", _
usernm, pword
Set dbrs = New ADODB.Recordset
dbrs.Open sqlstr, dbcon
End Sub
Sub return_customer()
Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
filenm = ThisWorkbook.Path & "\db.mdb"
sql = "SELECT DISTINCT buyer_name FROM table1 ORDER BY buyer_name ;"
Call getCn(adoconn, adors, sql, filenm, "", "")
cboCustomer.CopyFromRecordset adors
adors.Close
adoconn.Close
Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing
End Sub
After it, I would like to open the form, choose a customer in this
combobox, and the name of the customer selected will appear in a cell
of excel...
How can I do it???
Thanks in advance!!!
André.