Enter password to enable command buttons

E

Essexbug

Hi.

I am trying to build a form which hides a number of command buttons that I
want to make visible and enabled only when a user enters the password.

The form (frmMain_Menu) has a button that on click makes visible a text
box(txt_pword) and a command button (cmb_CheckPW).

I want it to check the text entered in txt_pword against Password in
tblPassword.
It is a text field, set as primary key and is limited to 8 characters in
length.

I would like it that when the command button is checked that the text in the
text box is checked against the tblpassword, password record and if they
match enable additional command buttons.

Please help!
 
N

NthDegree via AccessMonster.com

Let's assume your command button is called cmdCheckPwd and your form password
field is called strPassword, add a On Click event to the command button that
looks like the following:

Private Sub cmdCheckPwd_Click()

If IsNull(DLookup("[PasswordField]", "PasswordTable", "[PasswordField] = " &
strPassword)) Then
'do something if it doesnt match
Else
'do something if it does
End If

End Sub

The brackets arent needed unless you have spaces in your field names.
 
E

Essexbug

Sorry, perhaps I should explain myself more.

I am a beginner when it comes to using vba in access. I am not sure what
you mean by the term password field?

NthDegree via AccessMonster.com said:
Let's assume your command button is called cmdCheckPwd and your form password
field is called strPassword, add a On Click event to the command button that
looks like the following:

Private Sub cmdCheckPwd_Click()

If IsNull(DLookup("[PasswordField]", "PasswordTable", "[PasswordField] = " &
strPassword)) Then
'do something if it doesnt match
Else
'do something if it does
End If

End Sub

The brackets arent needed unless you have spaces in your field names.
Hi.

I am trying to build a form which hides a number of command buttons that I
want to make visible and enabled only when a user enters the password.

The form (frmMain_Menu) has a button that on click makes visible a text
box(txt_pword) and a command button (cmb_CheckPW).

I want it to check the text entered in txt_pword against Password in
tblPassword.
It is a text field, set as primary key and is limited to 8 characters in
length.

I would like it that when the command button is checked that the text in the
text box is checked against the tblpassword, password record and if they
match enable additional command buttons.

Please help!

--
Never let it be said that I was totally comitted to sanity. It is the dark
places of my mind that fascinate me.

NthDegree
 
E

Essexbug

also I have not used dlookup in vba before (what do you mean by
passwordtable?). Sorry but I need hand-holding through this please.

I would like to be able to understand why I am writing this code not just how.

Many thanks

Essexbug said:
Sorry, perhaps I should explain myself more.

I am a beginner when it comes to using vba in access. I am not sure what
you mean by the term password field?

NthDegree via AccessMonster.com said:
Let's assume your command button is called cmdCheckPwd and your form password
field is called strPassword, add a On Click event to the command button that
looks like the following:

Private Sub cmdCheckPwd_Click()

If IsNull(DLookup("[PasswordField]", "PasswordTable", "[PasswordField] = " &
strPassword)) Then
'do something if it doesnt match
Else
'do something if it does
End If

End Sub

The brackets arent needed unless you have spaces in your field names.
Hi.

I am trying to build a form which hides a number of command buttons that I
want to make visible and enabled only when a user enters the password.

The form (frmMain_Menu) has a button that on click makes visible a text
box(txt_pword) and a command button (cmb_CheckPW).

I want it to check the text entered in txt_pword against Password in
tblPassword.
It is a text field, set as primary key and is limited to 8 characters in
length.

I would like it that when the command button is checked that the text in the
text box is checked against the tblpassword, password record and if they
match enable additional command buttons.

Please help!

--
Never let it be said that I was totally comitted to sanity. It is the dark
places of my mind that fascinate me.

NthDegree
 
N

NthDegree via AccessMonster.com

Ok, no problem.

Let me do it using your field names:

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] = " &
txt_pword)) Then
'do something if it doesnt match
Else
'do something if it does
End If

End Sub

The DLookup (database Lookup function) is broken down like this:

First parameter ([Password]) = field to be returned from table (or query)
Second parameter (tblPassword) is the table (or query) to do the search on
Third parameter ("[Password] = " & txt_pword) is the search argument

If it finds a match then the field Password will contain the value, if no
match (the value of txt_pword doesnt match any of the tables Password fields),
dlookup returns a Null value.

Then in the 'do something" statements you can do things like field1.visible =
false or cmdbutton.visible = true (replace field1 and cmdbutton with your
form controls names).

Hope this helps.

also I have not used dlookup in vba before (what do you mean by
passwordtable?). Sorry but I need hand-holding through this please.

I would like to be able to understand why I am writing this code not just how.

Many thanks
Sorry, perhaps I should explain myself more.
[quoted text clipped - 36 lines]
 
E

Essexbug

Ok

I have inputed the code as advised, but i keep getting a syntax error. I
even pasted direct from your reply, here's the code.

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] = " &
Txt_PWord )) Then

MsgBox "Sorry the password you have entered is incorrect. Try again"
Else
cmbAddNew.Visible = True
End If

End Sub

What is wrong with the syntax as I assume it should be accepting it? I'm on
access 2002 btw

NthDegree via AccessMonster.com said:
Ok, no problem.

Let me do it using your field names:

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] = " &
txt_pword)) Then
'do something if it doesnt match
Else
'do something if it does
End If

End Sub

The DLookup (database Lookup function) is broken down like this:

First parameter ([Password]) = field to be returned from table (or query)
Second parameter (tblPassword) is the table (or query) to do the search on
Third parameter ("[Password] = " & txt_pword) is the search argument

If it finds a match then the field Password will contain the value, if no
match (the value of txt_pword doesnt match any of the tables Password fields),
dlookup returns a Null value.

Then in the 'do something" statements you can do things like field1.visible =
false or cmdbutton.visible = true (replace field1 and cmdbutton with your
form controls names).

Hope this helps.

also I have not used dlookup in vba before (what do you mean by
passwordtable?). Sorry but I need hand-holding through this please.

I would like to be able to understand why I am writing this code not just how.

Many thanks
Sorry, perhaps I should explain myself more.
[quoted text clipped - 36 lines]
Please help!
 
E

Essexbug

Also if i enter the code as below:

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] = " & Txt_PWord))
Then
MsgBox "Sorry the password you have entered is incorrect. Try again"
Else
cmbAddNew.Visible = True
End If

End Sub

Then I get a message box saying "Run-time error 2001: You canceled the
previous operation"

I appreciate all your help on this.

Essexbug said:
Ok

I have inputed the code as advised, but i keep getting a syntax error. I
even pasted direct from your reply, here's the code.

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] = " &
Txt_PWord )) Then

MsgBox "Sorry the password you have entered is incorrect. Try again"
Else
cmbAddNew.Visible = True
End If

End Sub

What is wrong with the syntax as I assume it should be accepting it? I'm on
access 2002 btw

NthDegree via AccessMonster.com said:
Ok, no problem.

Let me do it using your field names:

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] = " &
txt_pword)) Then
'do something if it doesnt match
Else
'do something if it does
End If

End Sub

The DLookup (database Lookup function) is broken down like this:

First parameter ([Password]) = field to be returned from table (or query)
Second parameter (tblPassword) is the table (or query) to do the search on
Third parameter ("[Password] = " & txt_pword) is the search argument

If it finds a match then the field Password will contain the value, if no
match (the value of txt_pword doesnt match any of the tables Password fields),
dlookup returns a Null value.

Then in the 'do something" statements you can do things like field1.visible =
false or cmdbutton.visible = true (replace field1 and cmdbutton with your
form controls names).

Hope this helps.

also I have not used dlookup in vba before (what do you mean by
passwordtable?). Sorry but I need hand-holding through this please.

I would like to be able to understand why I am writing this code not just how.

Many thanks

Sorry, perhaps I should explain myself more.

[quoted text clipped - 36 lines]

Please help!
 
E

Essexbug

Hi,

After a little trial and error I found that the following worked:

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] =
Form![Txt_PWord]")) Then
MsgBox "Sorry the password you have entered is incorrect. Try again"
Else
cmbAddNew.Visible = True
End If

End Sub

Many thanks Nth for your assistance and your patience.

Kind Regards, Jenni

Essexbug said:
Also if i enter the code as below:

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] = " & Txt_PWord))
Then
MsgBox "Sorry the password you have entered is incorrect. Try again"
Else
cmbAddNew.Visible = True
End If

End Sub

Then I get a message box saying "Run-time error 2001: You canceled the
previous operation"

I appreciate all your help on this.

Essexbug said:
Ok

I have inputed the code as advised, but i keep getting a syntax error. I
even pasted direct from your reply, here's the code.

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] = " &
Txt_PWord )) Then

MsgBox "Sorry the password you have entered is incorrect. Try again"
Else
cmbAddNew.Visible = True
End If

End Sub

What is wrong with the syntax as I assume it should be accepting it? I'm on
access 2002 btw

NthDegree via AccessMonster.com said:
Ok, no problem.

Let me do it using your field names:

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] = " &
txt_pword)) Then
'do something if it doesnt match
Else
'do something if it does
End If

End Sub

The DLookup (database Lookup function) is broken down like this:

First parameter ([Password]) = field to be returned from table (or query)
Second parameter (tblPassword) is the table (or query) to do the search on
Third parameter ("[Password] = " & txt_pword) is the search argument

If it finds a match then the field Password will contain the value, if no
match (the value of txt_pword doesnt match any of the tables Password fields),
dlookup returns a Null value.

Then in the 'do something" statements you can do things like field1.visible =
false or cmdbutton.visible = true (replace field1 and cmdbutton with your
form controls names).

Hope this helps.


Essexbug wrote:
also I have not used dlookup in vba before (what do you mean by
passwordtable?). Sorry but I need hand-holding through this please.

I would like to be able to understand why I am writing this code not just how.

Many thanks

Sorry, perhaps I should explain myself more.

[quoted text clipped - 36 lines]

Please help!
 
N

NthDegree via AccessMonster.com

Jenni,

My pleasure.
Hi,

After a little trial and error I found that the following worked:

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] =
Form![Txt_PWord]")) Then
MsgBox "Sorry the password you have entered is incorrect. Try again"
Else
cmbAddNew.Visible = True
End If

End Sub

Many thanks Nth for your assistance and your patience.

Kind Regards, Jenni
Also if i enter the code as below:
[quoted text clipped - 77 lines]
 
B

BeWyched

Hi Jenni

Just one small point - how secure do you want the password to be? Note that
anyone with MS Access can access your tables and read the password which may,
or may not, be an issue for you.

Cheers.

BW

NthDegree via AccessMonster.com said:
Jenni,

My pleasure.
Hi,

After a little trial and error I found that the following worked:

Private Sub cmb_CheckPW_Click()

If IsNull(DLookup("[Password]", "tblPassword", "[Password] =
Form![Txt_PWord]")) Then
MsgBox "Sorry the password you have entered is incorrect. Try again"
Else
cmbAddNew.Visible = True
End If

End Sub

Many thanks Nth for your assistance and your patience.

Kind Regards, Jenni
Also if i enter the code as below:
[quoted text clipped - 77 lines]
Please help!

--
Never let it be said that I was totally comitted to sanity. It is the dark
places of my mind that fascinate me.

NthDegree
 

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