Form VBA

  • Thread starter Thread starter tkaplan
  • Start date Start date
T

tkaplan

I'm trying to create a macro that will protect and unprotect 10 sheets
in a workbook.

i have the code to protect etc. i'm having a problem here:

i created a form named frmPassword where i have a text field called
My_Password.

what code would i use to open up that form and enter in a password,
then when i click ok to assign whatever was in My_Password to a
variable called My_Pass.

I tried My_Pass=frmPassword.My_Password but that doesnt work, probably
because i never opened the form.

any help?
 
1) Wherever you want to open the form from:
Load frmPassword
frmPassword.Show
Unload frmPassword

2) In the VB editor, Insert a Module (Insert>Module), if you don't already
have one. This needs to be in a General Module NOT a Form, Workbook,
Worksheet, Class or other Object module. Place the following at the top
(right below any Option Explicit statement and before any subs or
functions):
Public My_Pass as String
Give the module a name and save it:

3) In the Click event of your "OK" button on frmPassword:
My_Pass=Me.My_Password
frmPassword.Hide
(where My_Password is the name of the textbox on frmPassword)

The value entered on frmPassword should now be available to you throughout
the project in any VBA code as My_Pass.

HTH,
 

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

Back
Top