Article ID: 124901
Article Last Modified on 1/19/2007
Function Test_Login_Error (UserID, Password)
On Error GoTo Error_Trap
Dim mydb As Database
Dim myq As QueryDef
Set mydb = CurrentDB()
Set myq = mydb.CreateQueryDef("")
myq.connect = "ODBC;DSN=opus;UID=" & UserID & ";PWD=" & _
Password &";LANGUAGE=us_english;DATABASE=pubs"
myq.returnsrecords = False
' Any SQL statement will work below.
myq.sql = "select * from authors"
myq.Execute
Exit function
Error_Trap:
MsgBox "An error has occurred."
MsgBox Error
Exit Function
End Function
You can use a variation of this function with any form that requires an
ODBC login ID and password. Before logging the user in, use the code to
test the user's ID and password on the ODBC data source. Note that testing
with this function does not consume extra connections. When you reconnect
to the same data source, the same connection is used.
Function Login_Error (UserID, Password)
On Error GoTo Error_Trap2
Dim myws As WorkSpace, connstr As String
Dim mydb As Database
connstr = "ODBC;DSN=opus;UID=" & UserID & ";PWD=" & _
Password & ";LANGUAGE=us_english;DATABASE=pubs"
Set myws = DBEngine.Workspaces(0)
Set mydb = myws.OpenDatabase("", False, False, connstr)
mydb.Close
Exit Function
Error_Trap2:
MsgBox "An error has occurred."
MsgBox Error
Exit Function
End Function
?Login_Error("myuser","wrongpassword")
Keywords: kbprb kbprogramming kbusage KB124901