Get a Variable from a form Command Button

N

Not_a_notes_fan

Hi

I am very new to VB so treat me gently please!

I want to password protect a command button on a form. Basically I want
users to click button1 on form1 to open form2 in data entry mode, or button2
on form1 to ask for a simple password which will then open form2 in data edit
mode.

I am not concerned with user security levels etc, because the users will be
detered enough when they see a password prompt. The actual password can be
encoded within the VB code using an "if" statement to compare.

Thanks for your help!!
 
A

Alex Dybenko

Hi,
you can build a new form for password prompt, put textbox there with
"password" mask, and 2 buttons - ok and cancel, form have to be opened in
dialog mode (see docmd.openform options). both ok and cancel variables
should hide the form (me.visible=false), while OK button should set some
form's level public var to true, so you know that ok was pressed

then you open this form in your code, when some button pressed to get code
execution back and read password:

if Forms("PasswordDialog").txtPassword="mypassword" then
'password ok
end if

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 
N

Not_a_notes_fan

Thanks for your help on this.

I have tried your suggestion and am getting an Object Required error after
entering the password, before the main form opens.

This is the code I have:

Private Sub OK_cmd_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Me.Visible = False
If Form_Enter_Password.txtPassword = "passw0rd" Then
stDocName = "Data Edit Form"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End Sub
 
N

Not_a_notes_fan

Sorted it out.

Thanks again for your help.

(I was using Password as the name of the textbox which is a reserved name I
believe).
 

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