Importing Text Question

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
647
Office Version
  1. 2016
Platform
  1. Windows
Hi
Iam importing a text file by running a macro (access 2000), when a command button is clicked. If the file is not found I receive an error message "the jet enjine cannot find the file make sure the name is spell correctly etc. The problem is that if on click I first run a message box to allow the user the option to cancel the command. I don't get the error message, I want the error message to show if the files is not there.

This is my code. I did try to add an onerror goto , but then I recieved the erro message that I typed whether the file is found or not. :confused:

Private Sub ImportTextFile_Click()

Dim Msg, Style, Title, Response, MyString
Msg = "You are about to Import an OverDue text file that will Replace your current File. Do you want to Continue ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Caution" ' Define title.

' context.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
DoCmd.RunMacro "ImportReport"

' Perform some action.

Else
Exit Sub
End If
exit sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Put On Error GoTo ErrHandler in the begining of your code, and before end, insert following codes like:

...
Exit sub
ErrHandler:
MsgBox Err.Number & vbNewLine & Err.Description
End Sub

Tim
 
Upvote 0
Liz

What code are you actually using for the import?
 
Upvote 0
Hi thanks

I tried putting the code Tim suggested, but I only get a message box with 0 in it comming. up .

Norie I am using a maco that uses TransferText under fileName I have typed in the correct Path and file name. If I click directly on the macro or attached the macro to a command button I will get the error message if the file cannot be found. If I use and Event Procedure and use a messagebox to run the macro I do not receive the error message if the file is not located. The macro runs as is all is ok, but not data is imported.

The error is Should receive is The Microsoft Database Jet engine the Object Myfiles name. Make sure the object exists and that you spell its name and path correctly.

I would have thought I would have had MORE difficulty if I had wanted to surpress the message not receive it.
Thanks for you help
Liz


:oops: ErrHandler:
 
Upvote 0

Forum statistics

Threads
1,221,846
Messages
6,162,378
Members
451,760
Latest member
samue Thon Ajaladin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top