Error 424 - Object Requried

C

Chris

I have a form in MS Excel (Use the VB to create this form) on this form I have
a button that would allow me to browse and pick a file. Once I pick the file
I have another button that would let me import the file into the spread sheet
but I am get this Error 424 - object required.

Can someone help with this?
Code for Browse
Private Sub cmdBrowse_Click()
'Requires reference to Microsoft Office 11.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Dim PicFn As String
'Clear listbox contents.
'Me.FileList.RowSource = ""

'Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Allow user to make multiple selections in dialog box
.AllowMultiSelect = False

'Set the title of the dialog box.
.Title = "Please select an Excel or a Text File"
.InitialView = msoFileDialogViewDetails
.ButtonName = "Select a File"
'.InitialFileName = CurrentProject.Path & "\pictures"
'Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Data File", "*.XLS; *.txt"
.Filters.Add "All Files", "*.*"

'Show the dialog box. If the .Show method returns True, the
'user picked at least one file. If the .Show method returns
'False, the user clicked Cancel.
If .Show = True Then
''Loop through each file selected and add it to our list box.
For Each varFile In .SelectedItems
txtInputFile.Value = Format$(varFile)
Next
Dim ExcelApp As Excel.Application
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Workbooks.Open txtInputFile.Value
' ExcelApp.Sheets("Sheet1").PrintOut
ExcelApp.Workbooks.Close
Set ExcelApp = Nothing
End If
End With
End Sub
Code for import
'This would import the Current Month Data
Private Sub cmdImport_Click()
On Error GoTo ErrorCheck

varFilename = Me.txtInputFile
If IsNull(varFilename) Then
MsgBox "You must enter an input filename.", vbExclamation, " "
Me.txtInputFile.SetFocus
Exit Sub
End If


DoCmd.TransferText acImportDelim, , "Rate_Table_LIBOR_Swap ",
varFilename, True
Exit Sub

ErrorCheck:
Select Case Err.Number
Case 7874 'Import file not there to delete
Resume Next
Case Else
MsgBox "Error " & Err.Number & " - " & Err.Description
Exit Sub
End Select


'End Sub

Thanks in advance
 
C

Chris

Tom

No line is highlighted I am getting a pop up box with the error message.

Also Tom, Can you help with the error I'm gettimg with my previous ?
"Subject - Application to import and convert Data" I tryied your code but I
am getting some erors still
 
T

Tom Ogilvy

If you hit the debug button in the popup, then you should be taken to the VBE
and see a line highlighted.
 
T

Tim Williams

Private Sub cmdImport_Click()
'On Error GoTo ErrorCheck 'comment out this line to see the real error

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top