McDimwitty
Registered User.
- Local time
- Today, 11:57
- Joined
- Oct 23, 2007
- Messages
- 16
I am getting a compile error in the second sub in the OpenText statement.
Any idea why?
Private Function GetSelectedFile() As String
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.Filters.Clear
.Filters.Add "Excel Files", "*.xls"
.Filters.Add "All Files", "*.*"
If .Show = True Then
GetSelectedFile = .SelectedItems(1)
Else
GetSelectedFile = ""
End If
End With
End Function
Private Sub CmdImpStuff_Click()
On Error GoTo StuffImport_Err
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWBs As Excel.Workbooks
Dim xlWS As Excel.Worksheet
Dim strBookName As String
Dim temp As String
Set xlApp = CreateObject("Excel.Application")
Dim DelimFileName As String
DelimFileName = GetSelectedFile
If DelimFileName <> "" Then
DoCmd.SetWarnings False
'xlWBs.OpenText
xlWBs.OpenText(FileName:=DelimFileName, _
Origin:=437, StartRow:=2, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), _
Array(2, 2), Array(3, 1), Array(4, 2), Array(5, 4), Array(6, 2), Array(7, 2), Array(8, 2), _
Array(9, 1), Array(10, 2), Array(11, 1), Array(12, 2), Array(13, 1), Array(14, 1), Array(15 _
, 2), Array(16, 2), Array(17, 4), Array(18, 4), Array(19, 4), Array(20, 4), Array(21, 2), _
Array(22, 2), Array(23, 2), Array(24, 2), Array(25, 1), Array(26, 1), Array(27, 1)), _
TrailingMinusNumbers:=True)
xlWB = ActiveWorkbook
'xlWB.FullName
strBookName = (Left(xlWB.FullName, (Len(xlWB.FullName) - 4)) & "_temp.xls")
xlWB.SaveAs strBookName
DoCmd.OpenQuery "qdel_StuffData", acViewNormal, acEdit
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblStuff_RawData", FileName, True
xlWB.Close
' DoCmd.TransferText acImportDelim, , "tblStuff_RawData", FileName, False
Set xlApp = Nothing
Set xlWB = Nothing
Set xlWBs = Nothing
Set xlWS = Nothing
MsgBox "File uploaded Successfully.", vbOKOnly, "Upload Successful"
DoCmd.SetWarnings True
End If
StuffImport_Exit:
Exit Sub
StuffImport_Err:
MsgBox Error$
Resume StuffImport_Exit
End Sub
Any idea why?
Private Function GetSelectedFile() As String
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.Filters.Clear
.Filters.Add "Excel Files", "*.xls"
.Filters.Add "All Files", "*.*"
If .Show = True Then
GetSelectedFile = .SelectedItems(1)
Else
GetSelectedFile = ""
End If
End With
End Function
Private Sub CmdImpStuff_Click()
On Error GoTo StuffImport_Err
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWBs As Excel.Workbooks
Dim xlWS As Excel.Worksheet
Dim strBookName As String
Dim temp As String
Set xlApp = CreateObject("Excel.Application")
Dim DelimFileName As String
DelimFileName = GetSelectedFile
If DelimFileName <> "" Then
DoCmd.SetWarnings False
'xlWBs.OpenText
xlWBs.OpenText(FileName:=DelimFileName, _
Origin:=437, StartRow:=2, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), _
Array(2, 2), Array(3, 1), Array(4, 2), Array(5, 4), Array(6, 2), Array(7, 2), Array(8, 2), _
Array(9, 1), Array(10, 2), Array(11, 1), Array(12, 2), Array(13, 1), Array(14, 1), Array(15 _
, 2), Array(16, 2), Array(17, 4), Array(18, 4), Array(19, 4), Array(20, 4), Array(21, 2), _
Array(22, 2), Array(23, 2), Array(24, 2), Array(25, 1), Array(26, 1), Array(27, 1)), _
TrailingMinusNumbers:=True)
xlWB = ActiveWorkbook
'xlWB.FullName
strBookName = (Left(xlWB.FullName, (Len(xlWB.FullName) - 4)) & "_temp.xls")
xlWB.SaveAs strBookName
DoCmd.OpenQuery "qdel_StuffData", acViewNormal, acEdit
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblStuff_RawData", FileName, True
xlWB.Close
' DoCmd.TransferText acImportDelim, , "tblStuff_RawData", FileName, False
Set xlApp = Nothing
Set xlWB = Nothing
Set xlWBs = Nothing
Set xlWS = Nothing
MsgBox "File uploaded Successfully.", vbOKOnly, "Upload Successful"
DoCmd.SetWarnings True
End If
StuffImport_Exit:
Exit Sub
StuffImport_Err:
MsgBox Error$
Resume StuffImport_Exit
End Sub