Login Form

B

Bryan Hughes

Hello,
I have been trying to create a login form with a ClassModule to log users
into particular areas. I have made the form and the ClassModule but when I
click the cmdbtn nothing happens.

The cmdbtn is called cmdACM

The OnClick event looks like this:

Private Sub cmdACM_Click()
Dim PWT As New CMTestClass1

PWT.cpw Me!txtEMPID, Me!txtPassword

End Sub

The ClassModule is called CMTestClass1
The procedure looks like this:

Option Compare Database

Sub cpw(empid As Long, pw As String)
Dim cmd1 As Command
Dim strSQL As String
Dim prm1 As ADODB.Parameter
Dim rst1 As ADODB.Recordset


'Assign the command reference and connection
Set cmd1 = New ADODB.Command
cmd1.ActiveConnection = CurrentProject.Connection

'SQL statement with parameters & assign to cmd1
strSQL = "Parameters Secret Long;" & _
"SELECT StaffID, Password FROM Staff " & _
"WHERE StaffID=Secret"
cmd1.CommandText = strSQL
cmd1.CommandType = adCmdText

Set prm1 = cmd1.CreateParameter("Secret", adInteger, adParamInput)
prm1.Value = empid
cmd1.Parameters.Append prm1

'line for catching SQL syntax errors
' Debug.Print cmd1.CommandText

cmd1.Execute

Set rst1 = New ADODB.Recordset
rst1.Open cmd1
If rst1.Fields("Password") = pw Then
MsgBox "You are now authorized to make this change.",
vbInformation, "Update Client Information Authorized:"
Else
MsgBox "Invalid password. Try again or change password.",
vbCritical, "Incorrect Password:"
End If

End Sub

Why won't this work? What am I doing wrong?
Please Help
-Bryan
 
B

Bryan Hughes

Ed,

Thanks for the reply.

I thought about built in Security. The problem is this is a Client DB and
each client is assigned a Case Manager. Only the case manager assigned to
the record can update it, so I a need pw check before a CM can update
record.

Can the built in security do this?

-Bryan
 
E

Ed Jobe

No, you can't assign rights down to the record level, just db objects like
forms, reports.

BTW, in the previous code I sent, you need to AND the ID with the pw.
 
E

Ed Jobe

To open a form from the command button, use the DoCmd.OpenForm command. You
can access other forms via the Forms collection. From the login form, just
change the Enabled property of the fields on the first form. When you close
the login form, the previous form will have focus automatically.

'code in login form
Dim frm As Form_MyForm
Set frm = Forms!MyForm
frm.MyTextBox.Enabled = True
Unload Me
 

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

Similar Threads


Top