M
msaccess1986
Guest
I designing the login form in Access 2003.But I have many problem since the unique key (primary key) use Masked.
Access Structure
Staff (Table)
- StaffID (PK field)'masked as S0001 ,S0002 ; actual storing is 1,2 and so on
- Password (field)
- Position (field)
I want to to check StaffID and Password match with the Staff.StaffID and Staff.Password.
If correct password match the open Main Menu.
Meanwhile,assign their position to globle variable to globle_StaffPosition
Currently the StaffID,user can key in the actual data which is 1 or 2 or 3 to log in.....In fact,they will key in S0001 or S0002 to log in
And the globle_StaffPosition part how to assign it ? Is it my SQL command wrong ?
Sorry,I am new to VB & SQL
Hope someone can help me.....
Thanks for your reply
Access Structure
Staff (Table)
- StaffID (PK field)'masked as S0001 ,S0002 ; actual storing is 1,2 and so on
- Password (field)
- Position (field)
I want to to check StaffID and Password match with the Staff.StaffID and Staff.Password.
If correct password match the open Main Menu.
Meanwhile,assign their position to globle variable to globle_StaffPosition
Currently the StaffID,user can key in the actual data which is 1 or 2 or 3 to log in.....In fact,they will key in S0001 or S0002 to log in
And the globle_StaffPosition part how to assign it ? Is it my SQL command wrong ?
Private Sub okButton_Click()
Dim UserTxt1 As Long
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
If IsNull(Me.UserTxt) Then
MsgBox "Please enter a valid user name.", vbExclamation, "Invalid User Name"
Me.UserTxt.SetFocus
Exit Sub
ElseIf IsNull(Me.PassTxt) Then
MsgBox "Please enter a valid password.", vbExclamation, "Invalid Password"
Me.PassTxt.SetFocus
Exit Sub
End If
'Stupid method convert userInput & field data into long format to avoid datatype error
UserTxt1 = CLng(UserTxt)
MsgBox UserTxt1, vbInformation, "Welcome"
rs.Open "SELECT StaffID , Password FROM Staff WHERE( CLng(StaffID) = """ & UserTxt1 & """ AND Password = """ & Me.PassTxt & """)", _
CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If rs.EOF Then
MsgBox "Invalid user name or password. Please try again.", vbExclamation, "Error"
Me.UserTxt.SetFocus
Exit Sub
End If
'Error here,anyone know how to assign it ?
globle_StaffPosition = rs.Open "SELECT Position FROM Staff WHERE( CLng(StaffID) = """ & UserTxt1 & """)", CurrentProject.Connection , adOpenKeyset, adLockOptimistic
MsgBox "Login Successful.", vbInformation, "Welcome"
DoCmd.Close
DoCmd.OpenForm "Main menu", acNormal
Sorry,I am new to VB & SQL
Hope someone can help me.....
Thanks for your reply
Last edited: