VBA code to password protect and entry field?

  • Thread starter chris23892 via AccessMonster.com
  • Start date
C

chris23892 via AccessMonster.com

Hi all! Here's an interesting project.

In one of my forms in an acess DB, I have a text entry box. Now, I don't
want just anyone to be able to type garbage into this text box. I also do not
want to hide or lock it. I need to use it now and again.

IS there some code snippet I can use to that will prompt for a password to
unlock the text field?

An example would be IF one were to click on the text field, A prompt would
come up for a password. You enter the password and the text box would now be
active to acept typing. Otherwize the text box needs to be greyed out and
null (not active).

Thoughts on this?
 
C

CJ Ardash

There are a few events you could use to trigger a prompt for a password, On
Dirty, On Change, and On Got Focus. On Dirty is probably your best bet if
the text box and the form its on are tied to a field and table. On Change
works even if it isn't, but it's triggered once per character entered, so you
might want to build in a time delay. On Got Focus will be triggered every
time you click in the box or tab to it.

Of the three of them, On Got Focus would be my first choice.

Private Sub TextBox1_GotFocus
Dim strPassword as String

If Inputbox("Please enter the password:") <> strPassword Then
SomeOtherControl.SetFocus
TextBox1.Locked = True
End If
End Sub


Please let me know if this helps,
CJ
 
C

chris23892 via AccessMonster.com

fantastic...I'll give it a try and let you know. thanks for the insight. very
helpful information

CJ said:
There are a few events you could use to trigger a prompt for a password, On
Dirty, On Change, and On Got Focus. On Dirty is probably your best bet if
the text box and the form its on are tied to a field and table. On Change
works even if it isn't, but it's triggered once per character entered, so you
might want to build in a time delay. On Got Focus will be triggered every
time you click in the box or tab to it.

Of the three of them, On Got Focus would be my first choice.

Private Sub TextBox1_GotFocus
Dim strPassword as String

If Inputbox("Please enter the password:") <> strPassword Then
SomeOtherControl.SetFocus
TextBox1.Locked = True
End If
End Sub

Please let me know if this helps,
CJ
Hi all! Here's an interesting project.
[quoted text clipped - 11 lines]
Thoughts on this?
 

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