Code Conversion for Use in .adp

  • Thread starter Thread starter AB via AccessMonster.com
  • Start date Start date
A

AB via AccessMonster.com

I have successfully used the code below for a login form in an Access .mdb.

I am now working with an ADP file and the code does not work...

What is needed to use this with an ADP?

we need to have a table defined login vs a sql login


Thanks - AB

----------------------------

code below


Private Sub okButton_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
If IsNull(Me.txtUserName) Then
MsgBox "Please enter a valid user name.", vbExclamation, "Error"
Me.txtUserName.SetFocus
Exit Sub

End If
rs.Open "SELECT * FROM viewUsers WHERE(UserName = """ & Me.txtUserName &
""")", _
CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If rs.EOF Then
MsgBox "Invalid user name. Please try again.", vbExclamation, "Error"
Me.txtUserName.SetFocus
Exit Sub
End If
MsgBox "Login Successful.", vbInformation, "Confirm!"
Me.Visible = False


Exit Sub
End Sub
 
SQL Server (by default, at least) expects literal text values to be
delimited by single quotes, not double quotes. Most of the changes in the
following code are just to enable me to test it without your form and
database, the key change is the use of single quotes in the WHERE clause.

Public Function TestIt(txtUserName As Variant)

Dim strSQL As String

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
If IsNull(txtUserName) Then
MsgBox "Please enter a valid user name.", vbExclamation, "Error"
'Me.txtUserName.SetFocus
Exit Function

End If
strSQL = "SELECT * FROM Employees WHERE(LastName = '" & txtUserName & "')"
rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic

If rs.EOF Then
MsgBox "Invalid user name. Please try again.", vbExclamation, "Error"
'Me.txtUserName.SetFocus
Exit Function
End If
MsgBox "Login Successful.", vbInformation, "Confirm!"
'Me.Visible = False


Exit Function
End Function
 
Back
Top