Option Compare Database
Option Explicit
Function fncLoginError(strUserID As String, strPassword As String)
On Error GoTo LoginError
Dim wks As DAO.Workspace
Dim dbs As DAO.Database
Dim con As String
'Replace <DSN> with the actual DSN that points to your SQL Server.
con = "ODBC;DSN=<DSN>;UID=" & strUserID & ";PWD=" & strPassword & _
";DATABASE=Pubs"
Set wks = DBEngine.Workspaces(0)
Set dbs = wks.OpenDatabase("", False, False, con)
dbs.Close
Exit Function
LoginError:
MsgBox "An error has occurred."
MsgBox Err.Description
Exit Function
End Function