Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

quiting from sub after error in import text files

Status
Not open for further replies.

momon

Vendor
May 22, 2002
42
CA
Hello.

I have a button that imports a text file into the table. I have set the on click() property of the button as follows.

Private Sub Command34_Click()
On Error GoTo Err_Command34_click

DoCmd.TransferText , "WSPR Import Specification", "WSPECS", "C:\Database\WSPR.txt"

msgbox "success!"

Exit_Command34_Click:
Exit Sub

Err_Command34_click:
MsgBox Err.Description
Resume Exit_Command34_Click

End Sub

If there is an import error ( i.e. the record already exists in the table ), I want to 'Exit Sub' so that it doesn't display the "success" msgbox...

Also, does anyone know how to change the system message for text import errors?

thanks in advance
 
I think what you are after is something like :-

Private Sub Command34_Click()
On Error GoTo Err_Command34_click

DoCmd.SetWarnings False
DoCmd.TransferText , "WSPR Import Specification", "WSPECS", "C:\Database\WSPR.txt"

msgbox "success!"

Exit_Command34_Click:
DoCmd.SetWarnings True
Exit Sub

Err_Command34_click:
SELECT CASE Err.Number
Case = textImportErrorNumber
MsgBox "Your custom message here ", , "Title"
Case = textOtherErrorYouWantToTrapNumber
MsgBox "Your Other custom message", , "Title"
Case Else
MsgBox Err.Description, , Err.Number
Resume Exit_Command34_Click
End Select
End Sub



'ope-that-'elps.

G LS
 
thanks for your help littlesmudge.

Unfortunately, there still seems to be a problem.
The program seems to drop through regardless of whether there is an error or not.

Let me explain the situation in more detail.
I have a button that when clicked, imports one record from a textfile into the table. The primary key is set to two fields in the table, so access will automatically display a WARNING message if trying to import duplicates.

With the warning messages disabled (the code above),DoCmd.SetWarnings False, the program simply goes through and displays "success", without going to 'On Error GoTo Err_Command34_click'.


I guess the solution to the problem is to somehow get the program to goto 'On Error GoTo Err_Command34_click' when there is a WARNING or an ERROR.

Does anyone know how to do this?

Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top