Code Conversion for Use in .adp

  • Thread starter AB via AccessMonster.com
  • 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
 
B

Brendan Reynolds

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top