PDA

View Full Version : Solved: Input Box



Dowsey1977
12-08-2005, 08:10 AM
Hi,

I have a form that shows when I open my spreadsheet.

In this form is a textbox where the user has to enter their name.

The below code outlines what I already have


Dim Name
Name = TextBox1.Value
Unload Me
If Password = "Name1" Then
Sheets("ControlSheet").Visible = True
Sheets("ENTER PASSWORD").Visible = False
Else
If Password = "Name2" Then
Sheets("ControlSheet").Visible = True
Sheets("ENTER").Visible = False
Else
MsgBox "That is not a valid name. Please ensure you do not have CAPS LOCK on because names are case sensitive" & vbCrLf & vbCrLf & _
"Please re-enter your name", vbCritical + vbOKOnly, "Error"
entry.Show
End If
End If
End Sub

What I want to do is put something into the Initialise code of another form so that if Name declared in the above code equals Name1 to call another macro.

So in the other form I have:
If Name = "Name1" Then
Call ReadOnly
End If


But it doesn't seem to recognise the Name...any ideas?

ThAnKs in advance!

Bob Phillips
12-08-2005, 08:21 AM
Hi,

I have a form that shows when I open my spreadsheet.

In this form is a textbox where the user has to enter their name.

The below code outlines what I already have


Dim Name
Name = TextBox1.Value
Unload Me
If Password = "Name1" Then
Sheets("ControlSheet").Visible = True
Sheets("ENTER PASSWORD").Visible = False
Else
If Password = "Name2" Then
Sheets("ControlSheet").Visible = True
Sheets("ENTER").Visible = False
Else
MsgBox "That is not a valid name. Please ensure you do not have CAPS LOCK on because names are case sensitive" & vbCrLf & vbCrLf & _
"Please re-enter your name", vbCritical + vbOKOnly, "Error"
entry.Show
End If
End If
End Sub

What I want to do is put something into the Initialise code of another form so that if Name declared in the above code equals Name1 to call another macro.

So in the other form I have:
If Name = "Name1" Then
Call ReadOnly
End If


But it doesn't seem to recognise the Name...any ideas?

ThAnKs in advance!

Either pass Name as an argument to the second macro, or declare it as a Global variable.

BTW N ame is not a good name for a variable.

Dowsey1977
12-08-2005, 08:33 AM
Ok, declaring it as a Global Variable sounds best, as it is likely to be used in more than macro, but not sure how I would do this, any chance you could advise!

And note taken, will rename it from Name once I'm clear what I'm doing.

tkaplan
12-08-2005, 08:52 AM
to declare a global variable, after the "option explicit" line, put the variable there - such as :
Option Explicit
Dim i As Long

sub.....

Dowsey1977
12-08-2005, 08:56 AM
Excellent, many thanks! Worked a treat!

One more question...
Basically, I am locking controls on a form if certain 'names' are entered. But I've just thought that people can still unhide the relating sheets and change on there. Is there anyway to stop the ability to unhide sheets or disable selection on sheets?

Bob Phillips
12-08-2005, 09:33 AM
Excellent, many thanks! Worked a treat!

One more question...
Basically, I am locking controls on a form if certain 'names' are entered. But I've just thought that people can still unhide the relating sheets and change on there. Is there anyway to stop the ability to unhide sheets or disable selection on sheets?

Make the sheets very hiiden, you can't unhide them from Excel

Activesheet.Visible = xlSheetVeryHidden

Dowsey1977
12-08-2005, 09:44 AM
Many thanks for all your help!

Dowsey1977
12-09-2005, 02:26 AM
This is solved, however, I am trying to mark it as SOVLED using the thread tools, but when I click on the link it just jumps to the bottom of the page!

lucas
12-09-2005, 08:26 AM
This is solved, however, I am trying to mark it as SOVLED using the thread tools, but when I click on the link it just jumps to the bottom of the page!

I marked the thread solved for you Dowsey