VBA code to password protect and entry field?

  • Follow


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?

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-modules/201002/1

0
Reply chris23892 2/22/2010 7:57:11 PM

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

"chris23892 via AccessMonster.com" wrote:

> 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?
> 
> -- 
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-modules/201002/1
> 
> .
> 
0
Reply Utf 2/22/2010 9:14:01 PM


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

CJ Ardash wrote:
>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?

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-modules/201002/1

0
Reply chris23892 2/22/2010 9:23:04 PM

2 Replies
1685 Views

(page loaded in 0.056 seconds)


Reply: