Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / March 2008

Tip: Looking for answers? Try searching our database.

drop-down list - can the list be populated in code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BillE - 21 Mar 2008 13:51 GMT
Can a dropdown list be populated in code?

I would like to use ado to retrieve a list from an Access database with VBA
and use it to populate a dropdown.

Alternatively, could I populate a group of cells and then dynamically (in
VBA code) set the dropdown list source to the group of cells?

Thanks
Bill
JP - 21 Mar 2008 18:39 GMT
I found some sample code here:

http://tinyurl.com/3brzjy
http://tinyurl.com/3ywvhr

Does that help?

--JP

> Can a dropdown list be populated in code?
>
[quoted text clipped - 6 lines]
> Thanks
> Bill
Mika Oukka - 21 Mar 2008 19:22 GMT
The following should generate the data from your access table. Take it from
here.

Mika Oukka - IT-Consultant

Sub Import_From_Access()
   'Check the correct Microsoft the correct ActiveX DataObjects Library
   Dim cnt As ADODB.Connection
   Dim rst1 As ADODB.Recordset
   Dim stDB As String, stSQL1 As String
   Dim stConn As String
   Dim wbBook As Workbook
   Dim wsSheet1 As Worksheet
   Dim lnField As Long, lnCount As Long

   Set cnt = New ADODB.Connection
   Set rst1 = New ADODB.Recordset
    Set wbBook = ThisWorkbook
   Set wsSheet1 = wbBook.Worksheets(1)

   'Set the correct path below******************
   stDB = "c:\temp\test\db1.mdb"
   '******************
   stConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
   & "Data Source=" & stDB & ";"

    'The 1st raw SQL-statement to be executed.
   stSQL1 = "SELECT Tbl1.* FROM Tbl1;"

      'Clear the worksheet.
   wsSheet1.Range("A1").CurrentRegion.Clear

   With cnt
       .Open (stConn) 'Open the connection.
       .CursorLocation = adUseClient 'Necessary to disconnect the
recordset.
   End With

   With rst1
       .Open stSQL1, cnt 'Create the recordset.
       Set .ActiveConnection = Nothing 'Disconnect the recordset.
   End With

   With wsSheet1
       .Cells(1, 1).CopyFromRecordset rst1 'Copy the 1st recordset.
   End With

   rst1.Close
   Set rst1 = Nothing

   cnt.Close
   Set cnt = Nothing
End Sub

> Can a dropdown list be populated in code?
>
[quoted text clipped - 6 lines]
> Thanks
> Bill

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.