Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jun 2003
    Posts
    238
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error Message (Access 2000)

    In the past someone here helped me create VB code to have a button export a query to excel with one click
    My problem is now I noticed if i click cancel instead of save i get an error
    Here is my code that i have right now....

    rivate Sub Command_Transfer_xcel_file_Click()
    'exports file as spreadsheet then asks to quit
    'Shows SaveDialog because no file name given
    DoCmd.OutputTo acOutputQuery, "Work_Screen_Material_List Query", acFormatXLS
    End Sub

    Any ideas on what i can do to avoid the error when I Click cancel??

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Error Message (Access 2000)

    The error you get is probably error # 2501 - operation canceled by user. You can trap this error:

    Private Sub Command_Transfer_xcel_file_Click()
    'exports file as spreadsheet then asks to quit
    'Shows SaveDialog because no file name given

    On Error GoTo ErrHandler
    DoCmd.OutputTo acOutputQuery, "Work_Screen_Material_List Query", acFormatXLS
    Exit Sub

    ErrHandler:
    If Not (Err = 2501) Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •