import file

  • Thread starter Thread starter VJ
  • Start date Start date
V

VJ

hi all,

I create a button on form to import file to table;

Private Sub Cmd_Get_Data_Click()
DoCmd.RunCommand (acCmdImport)
End Sub

i does work properly. but let say if i cancel the
importing process halfway,it prompted me run-time
error '2501' window (the run command action was
canceled).how do i get rid of this?anything miss in the
code?

thanks
 
Hi, VJ.
anything miss in the code?
Yes. You're missing the error handling. Try something like the following:

------------ *** Start code *** ------------

Private Sub Cmd_Get_Data_Click()

On Error GoTo ErrHandler

DoCmd.RunCommand (acCmdImport)

Exit Sub

ErrHandler:

'----------------------------------------------------------------------
' Determine whether user cancelled the import.
'----------------------------------------------------------------------

If (Err.Number = 2501) Then ' Could also replace 2501 with a
constant.
Resume Next
Else
MsgBox "Error in Cmd_Get_Data_Click( )" & vbCrLf & _
"in " & Me.Name & " form." & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
End If

End Sub

------------ *** End code *** ------------
HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.
 
Back
Top