ACC2: How to Trap SQL ODBC Login Cancel Error (122250)



The information in this article applies to:

  • Microsoft Access 2.0

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


Modification Type:MajorLast Reviewed:11/6/2000
Keywords:kberrmsg kbhowto kbusage KB122250