Scott A. Jones wrote:
I have an Access front end connecting to an SQL Server back-end. When the
application opens, I run a small test to determine if the SQL Server is
available. If it is not, I have code to trap the 'On Error' event.
Unfortunately, a 'SQL Server Login' dialog appears before my 'On Error' code
has a chance to run. Does anybody know how to prevent the dialog from
appearing? Suppressing warnings (DoCmd.SetWarnings FALSE) has no effect.
I have the same problem trying to open a database in DAO, no matter what
options I put into OpenDatabase() it will still prompt if the password
is wrong, etc. So I pop in a little bit of ADO...
Function CanOpenSQLDbLB(pstrServer As String, pstrDb As String, pstrUser
As String, pstrPassword As String, Optional pfReportError As Boolean =
True) As Boolean
' Error Trapped: 04/02/2003 09:50:00 Admin
On Error GoTo CanOpenSQLDbLB_Err
' try late binding
Dim objConn As Object
Dim strConn As String
Dim strError As String, lngErr As Long
Const cstrSQLErr = "[Microsoft][ODBC SQL Server Driver][SQL Server]"
Set objConn = CreateObject("ADODB.Connection")
strConn = strConn & "DRIVER=SQL Server"
strConn = strConn & ";SERVER=" & pstrServer
strConn = strConn & ";APP=" & Application.Name
strConn = strConn & ";WSID=AWorkstation"
strConn = strConn & ";DATABASE=" & pstrDb
objConn.Open strConn, pstrUser, pstrPassword
' Q'PLAGH
CanOpenSQLDbLB = True
CanOpenSQLDbLB_Exit:
On Error Resume Next
objConn.Close
Set objConn = Nothing
Exit Function
CanOpenSQLDbLB_Err:
lngErr = Err.Number
strError = Err.Description
'MsgBox strError
If InStr(1, strError, cstrSQLErr) Then
strError = "Error reported by server" & vbCr & vbCr &
Replace(strError, cstrSQLErr, "")
End If
'Debug.Print strError
Select Case lngErr
Case Else
If pfReportError Then
MsgBox strError, 16, "Error #" & Err & " Attempting to
open server database"
End If
End Select
Resume CanOpenSQLDbLB_Exit
End Function
--
\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\