need a small help in code adjustment

oliver916

Registered User.
Local time
Today, 21:25
Joined
Nov 24, 2009
Messages
32
i have a form as a login form
the user must put a fixed user name & Password to enter
i want a small adjustment to make the form accept another password at 1\1\2010

Like
if date..... the password is....

else
if date..... the password is ..............


& Here is the form:in the attachment
& Thanks for all
 

Attachments

I would likely put the date/password combination's in a table, but

Code:
Dim strPassword As String

If Date() > #12/31/09# Then
  strPassword = "abc"
Else
  strPassword = "def"
End If
 
I use a method suggseted by Paul. I use a table called tbl_users this has the following fields user name, password and password expiry date.

When the user logs in, I use a Dlookup to check if the password has expired and force the user to change their password. When the user changes their password, the password expiry date set to a new date, in my case it is 30 days after the current date. We have a rule where password must be changed after 30 days etc.
 
The Code is giving me Error
type mismatch
What to do?
 
This Is My Code
Code:
Option Compare Database
Public LngInterval As Long
Private Sub CmdClose_Click()
    DoCmd.Quit
End Sub

Private Sub CmdLogin_Click()
On Error GoTo Err_CmdLogin_Click

If Me.TxtUser = "Transport" And Me.TxtPWD = "amstpt" Then

    MsgBox "Login Successed", vbInformation + vbInformation, "Login"
    
    DoCmd.Close
    DoCmd.OpenForm "frm Main"
End If


Exit_CmdLogin_Click:
    Exit Sub

Err_CmdLogin_Click:
    MsgBox Err.Description
    Resume Exit_CmdLogin_Click
End Sub

& The Form Is Attached
 
Sorry,I do not have 2007 but I copied your code into a new form in my 2003 version and there was no problem with the code. I did not create the form frm main.

Comment out the line DoCmd.OpenForm "frm Main" to check if the code is causing the problem or when you open the frm main that is causing the problem.
 
no
that is my code before i entre the code that pbaldy
Give it to me

When i entre the code Its Comming the error
 
When I added Paul's code as shown in bold there is no error

Private Sub CmdLogin_Click()
On Error GoTo Err_CmdLogin_Click
Dim strPassword As String

If Me.txtuser = "Transport" And Me.TxtPWD = "amstpt" Then
If Date > #12/31/2009# Then
strPassword = "abc"
Else
strPassword = "def"
End If

MsgBox "Login Successed", vbInformation + vbInformation, "Login"


DoCmd.Close
DoCmd.OpenForm "frm Main"
End If

Exit_CmdLogin_Click:
Exit Sub
Err_CmdLogin_Click:
MsgBox Err.Description
Resume Exit_CmdLogin_Click
End Sub

You will need a table to store the new password otherwise the new password as per the above code is useless.
 
On what line does it error? You may need to comment out the error handler.
 
type mismatch genrally relates to dates/numbers/strings being compared illegally as it were.

so a date is a particular variable type, and has to be surrounded by # characters, when used directly

hence as paul pointed out #12/31/09# (US variant)

Now if you have entered a string, and try to compare it to a date, you will get a mismatch error. As I say, numbers, strings, and dates are all different, and cannot be compared directly. The compiler/debugger should highlight the error line, to make it easier to resolve.
 

Users who are viewing this thread

Back
Top Bottom