ACC2: How to Trap SQL ODBC Login Cancel ErrorLast reviewed: May 20, 1997Article ID: Q122250 |
The information in this article applies to:
SUMMARYAdvanced: 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 INFORMATIONThe 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
REFERENCESMicrosoft Access "Building Applications," version 2.0, Chapter 10, "Handling Run-Time Errors," pages 221-238
|
Additional query words: odbc kbhowto
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |