ACC2: How to Trap SQL ODBC Login Cancel ErrorID: Q122250
|
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.
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
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
Issue type : kbhowto
Last Reviewed: April 8, 1999