Thread: Form VBA
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
George Nicholson[_2_] George Nicholson[_2_] is offline
external usenet poster
 
Posts: 170
Default Form VBA

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

2) In the VB editor, Insert a Module (InsertModule), 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,
--
George Nicholson

Remove 'Junk' from return address.


"tkaplan" wrote in
message ...

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 he

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?


--
tkaplan
------------------------------------------------------------------------
tkaplan's Profile:
http://www.excelforum.com/member.php...o&userid=22987
View this thread: http://www.excelforum.com/showthread...hreadid=376377