Catching Errors

  • Thread starter chris0309 via AccessMonster.com
  • Start date
C

chris0309 via AccessMonster.com

Hi All,

Im using a DoCmd.TransferText command to upload a file to the database. If
there is no file or the file name is misspelled then the first error message
appears. However if the user clicks and uploads the database and then clicks
on the button again then I get a message up saying "Microsoft Office Access
was unable to append all the data to the table" im trying to catch this
message so i can display my own message as ive done with the first error
message.

Can anyone help please?

The code im using is below. Thanks

NoFileError:

If Err.Number = 3011 Then
MsgBox ("There is no file within the C drive called test.txt")
End If

If Err.Number Then
MsgBox ("You have already uploaded the new file to the database")
End If
 
D

DStegon via AccessMonster.com

If Err.Number Then
MsgBox ("You have already uploaded the new file to the database")
End If

err.number is not boolean, but a number. You are testing for a conditonal
true in the if statement.

Also, Why check against an "error" to trap a file not being found??

much better to use a function built for such testing

Dim fso As New FileSystemObject
Dim PathToFile as String

PathToFile = "C:\Test.txt"
If Not fso.FileExists(PathToFile ) Then
MsgBox "There is no file within the C drive called " & PathToFile
end if

you could have an inputbox to have them enter the text or better yet put and
opendialog control into use so they could actually pick from the computer
file system.

As far as "catching" the other error, it sounds like you are trying to add
the data and there is a unique index that is keeping you from adding records.
Do you need the txt file after it is imported? you could copy it to another
folder after importing it which would then delete it or just move it to
another folder (using the same fso object.

You cuold create a table that stores the name of the files that are imported
and check against that table before allowing the transfer. So after the file
has been transfered add the path of the file to the table as a string. Then
when someone clicks on the button again you first check to see if the path
already exists in the table and if it does then "exit kindly" with

MsgBox "You have already uploaded the new file to the database"
 

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