Microsoft KB Archive/122250

= ACC2: How to Trap SQL ODBC Login Cancel Error =

Article ID: 122250

Article Last Modified on 11/6/2000

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q122250



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, "", "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

