ACC2: How to Trap SQL ODBC Login Cancel Error

Last reviewed: May 20, 1997
Article ID: Q122250
The information in this article applies to:
  • Microsoft Access version 2.0

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

If you choose Cancel when you are logging in to a SQL Server database with Access Basic code, you receive the run-time error message "Operation canceled by user." This article describes how to trap this error.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Access Basic, please refer to the "Building Applications" manual.

MORE INFORMATION

The following sample function demonstrates how to trap the error described in the "Summary" section above. To use this function, first create it in a module, and then type "?TryLogin()" (without quotation marks) in the Immediate window.

NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

   '*********************
   ' Declarations section
   '*********************
   Option Explicit

   '***************************
   ' Sample function TryLogin()
   '***************************
   Function TryLogin ()
      On Error GoTo LoginError
      DoCmd TransferDatabase A_ATTACH, "<SQL Database>", "ODBC;", _
       a_table, "dbo.authors", "dbo_authors"
      MsgBox "Successful Attachment!"
   Exit Function

   LoginError:
      If Err = 3059 Then
         MsgBox "You canceled the login."
      Else
         MsgBox Error$
      End If
      Exit Function
   End Function

REFERENCES

Microsoft Access "Building Applications," version 2.0, Chapter 10, "Handling Run-Time Errors," pages 221-238


Additional query words: odbc kbhowto
Keywords : kberrmsg kbusage OdbcProb
Version : 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 20, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.