Run time Error

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

chris0309 via AccessMonster.com

Hi All,

I have got a transfer text statement to work which imports the new data from
the file ito the database table. However when the file is not there or miss
spelt its bringing up a run time error 3011. What im trying to do within the
code below is to catch the run time error and replace with my own message
however I get get it to work, its still bringing up the error.

Anyone got any ideas, much appricated.

Chris

Private Sub Command18_Click()

DoCmd.TransferText , "Test Import Specification", "Tabe1", "C:\test.csv",
True

message = MsgBox("File Upload complete", YesNo, "File Upload")

Me.Performance_Metrics_Capture_Job_Data_Sub_Form.SetFocus
Me.Command18.Enabled = False

End Sub

Private Sub Form_Error(DataErr As Integer, Response As Integer)

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

End If
End Sub
 
E

ErezM via AccessMonster.com

hi
in this specific case, if you know the problem is the file being missing,
then check for it's existance before the transfer, like:

Private Sub Command18_Click()

if Dir("C:\test.csv")<>"" then
DoCmd.TransferText , "Test Import Specification", "Tabe1", "C:\test.
csv",True
else
msgbox "the file is missing"
End If

or trap the error inside the subroutine:

Private Sub Command18_Click()
On Error Goto NoFileError

DoCmd.TransferText , "Test Import Specification", "Tabe1", "C:\test.csv",True
message = MsgBox("File Upload complete", YesNo, "File Upload")

Exit sub

NoFileError:

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


good luck
Erez
 
C

chris0309 via AccessMonster.com

That worked, thanks so much. Cheers
hi
in this specific case, if you know the problem is the file being missing,
then check for it's existance before the transfer, like:

Private Sub Command18_Click()

if Dir("C:\test.csv")<>"" then
DoCmd.TransferText , "Test Import Specification", "Tabe1", "C:\test.
csv",True
else
msgbox "the file is missing"
End If

or trap the error inside the subroutine:

Private Sub Command18_Click()
On Error Goto NoFileError

DoCmd.TransferText , "Test Import Specification", "Tabe1", "C:\test.csv",True
message = MsgBox("File Upload complete", YesNo, "File Upload")

Exit sub

NoFileError:

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

good luck
Erez
[quoted text clipped - 27 lines]
End If
End Sub
 

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