password

Sangpo

Registered User.
Local time
Tomorrow, 05:34
Joined
Jul 7, 2012
Messages
35
Dear Sir/madam(s)
For security reason I have written following set of codes to open the form called editRecordF. Is it possible to use this single set of same codes to open other forms?

Private Sub cmdOK_Click()
Set db = CurrentDb
Set rs = db.OpenRecordset("UserT", DB_OPEN_DYNASET)
rs.FindFirst "password='" & CStr(textpw) & "'"
If rs.NoMatch Then
MsgBox ("Sorry, Your Password is incorrect.")
Else
DoCmd.Close acForm, "PasswordaddF", acNosave
DoCmd.OpenForm ("editRecordF")
End If
End Sub
 
dear jon sir,

I have gone through the link that explains about procedure and module. Since I m in learning stage, I really rlealy cannot undestand much.
thanks alot
 
Its quicker & easier to use the dlookup() function in your case

Code:
Private Sub cmdOK_Click()
If dlookup("count(*)","UserT","password= '" & CStr(textpw) & "'") = 0 then
    MsgBox "Sorry, Your Password is incorrect."
Else
    DoCmd.Close acForm, "PasswordaddF", acNosave
    DoCmd.OpenForm ("editRecordF")
End If
End Sub

You can use it in all your forms as long as cmdOK & textpw exist there
 
hellow Sir.

Please refer to the below code that u have suggested. U know Sir this code will only open the form which I have named as editRecordF . I have marked the name of form with #######. So i wanted to know if there is any possibility to call this set of code from anywhere within the database to open the other forms other than the form I have mentioned here. Thanks

Private Sub cmdOK_Click()
If dlookup("count(*)","UserT","password= '" & CStr(textpw) & "'") = 0 then
MsgBox "Sorry, Your Password is incorrect."
Else
DoCmd.Close acForm, "PasswordaddF", acNosave
DoCmd.OpenForm ("editRecordF")#########
End If
End Sub
 
Private Sub cmdOK_Click()
If dlookup("count(*)","UserT","password= '" & CStr(textpw) & "'") = 0 then
MsgBox "Sorry, Your Password is incorrect."
Else
DoCmd.Close acForm, "PasswordaddF", acNosave
DoCmd.OpenForm ("editRecordF")
End If
End Sub

Sir,

I meant to say that this code will only open the this form """""DoCmd.OpenForm ("editRecordF")"""""""". This will not open other form unless I changed the name of form here. Is there anyway to call this same codes (using module or function)rather keep changing name of form.

sorry for bothering again and again.
 
Of course

Put the below in a module

Code:
Sub CheckPassword(formToOpen as string)
If dlookup("count(*)","UserT","password= '" & CStr(textpw) & "'") = 0 then
MsgBox "Sorry, Your Password is incorrect."
Else
DoCmd.Close acForm, "PasswordaddF", acNosave
DoCmd.OpenForm formToOpen
End If
End Sub
 
okay Sir, But how do I call that code from module (or what code should I write in PasswordAddF form where textbox name =textpw and command button name= cmdOK)

Thank you sir,
sangpo
 
You can call the above code by writing the following:

CheckPassword "YourFormNameHere"
 
Dear G37sam Sir,

The below is a part of code suggested me for data searching. This code is simple and short which is better than the code I have been using. Thank you for that. But i would appreciate if you explain how does this codes work.

MY QUESTION IS , WHAT DOES ("count(*)" ) AND =0 MEAN?

If dlookup("count(*)","UserT","password= '" & CStr(textpw) & "'") = 0 then
 
You're basically asking Access to count the records, if they're equal to zero (aka no records) then hide the subform.
 

Users who are viewing this thread

Back
Top Bottom