token_remedie
Registered User.
- Local time
- Today, 09:39
- Joined
- Jul 7, 2011
- Messages
- 78
hey, what am I doing wrong here?
so far it lets the user select a file, adds the worksheets to a combobox
now on the afterupdate() in the combo box i want to docmd.transfer spreadsheet based on the selection in the combobox. here's the code so far:
so far it lets the user select a file, adds the worksheets to a combobox
now on the afterupdate() in the combo box i want to docmd.transfer spreadsheet based on the selection in the combobox. here's the code so far:
Code:
Private strPathAndFile As String ' this is in general declarations
Option Compare Database
Private Sub Combo4_AfterUpdate()
DoCmd.TransferSpreadsheet acImport, , "importtable", strPathAndFile, True
End Sub
Private Sub Command0_Click()
Dim fd As FileDialog
Dim strfile As String
Dim strsearchpath As String
Dim strPathAndFile As String
Dim strSql As String
Dim MyXLApp As Excel.Application
Dim MyXLWorkBook As Excel.Workbook
Set fd = Application.FileDialog(msoFileDialogOpen)
'searchpath is set at c:\ for now, needs to be changed when live
strsearchpath = "c:\"
With fd
.AllowMultiSelect = False
.Filters.Add "Excel Files", "*.xlsx", 1
.Title = "locate files"
.InitialFileName = strsearchpath
.Show
End With
strPathAndFile = fd.SelectedItems(1)
If strPathAndFile <> vbNullString Then
MsgBox "file chosen = " & strPathAndFile
Set MyXLApp = New Excel.Application
Set MyXLWorkBook = MyXLApp.Workbooks.Open(strPathAndFile)
For i = 1 To MyXLWorkBook.Sheets.Count
Set myXLSheet = MyXLWorkBook.Sheets(i)
myXLSheet.Select
Combo4.AddItem myXLSheet.Name
Next
End If
End Sub
Private Sub Form_Close()
Combo4.ListItemsEditForm = ""
End Sub