Friday
Registered User.
- Local time
- Today, 10:11
- Joined
- Apr 11, 2003
- Messages
- 542
I stopped programming in Access about 12 years ago. Now I'm retired, working on a genealogy project, and had the idea of combining my DNA matches from several different labs into a database, where I narrow down particular matches based on a chromosome. So I've got the workbook with 22 sheets in it, one for each chromosome. I want to be able to select the worksheet from a combo box and then import it into my DB. The import part was easy. Populating the combo box has proven problematic. I haven't coded for years and years. Someone please look at this code and tell me why it doesn't;t work. It does not throw an error, the combo box just doesn't populate.
Code Tags Added by UG
Please use Code Tags when posting VBA Code
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Code Tags Added by UG
Please use Code Tags when posting VBA Code
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Code:
Dim xlObj As Object
Dim xlWb As Object
Dim varSheet As Variant
Dim i As Integer
On Error GoTo errTrap
Set xlObj = CreateObject("Excel.Application")
Set xlWb = xlObj.Workbooks.Open("C:\Users\mulde\FamilyHistory\DNAMatches.xlsx")
'clear the content of your combobox first
For i = Me.cboSheets.ListCount - 1 To 0 Step -1
Me.cboSheets.RemoveItem (i)
Next
'now add sheet names
For Each varSheet In xlWb.Worksheets
Me.cboSheets.AddItem varSheet.Name
Next
'were done
Me.cboSheets.Requery
Me.cboSheets = ""
'housekeeping
Set varSheet = Nothing
xlWb.Close False
Set xlWb = Nothing
xlObj.Quit
Set xlObj = Nothing
Exit Sub
errTrap:
Debug.Print "The error was " & Err.Number & " " & Err.Description
' in a code window press Control+G
Err.Clear
On Error Resume Next
Last edited by a moderator: