Consulting

Results 1 to 9 of 9

Thread: Solved: Input Box

  1. #1

    Cool Solved: Input Box

    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

    [VBA]
    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[/VBA]

    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:
    [VBA] If Name = "Name1" Then
    Call ReadOnly
    End If
    [/VBA]

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

    ThAnKs in advance!
    We're a Kingdom, and we're United!!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Dowsey1977
    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

    [VBA]
    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[/VBA]

    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:
    [VBA] If Name = "Name1" Then
    Call ReadOnly
    End If
    [/VBA]

    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.

  3. #3
    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.
    We're a Kingdom, and we're United!!

  4. #4
    to declare a global variable, after the "option explicit" line, put the variable there - such as :
    Option Explicit
    Dim i As Long

    sub.....

  5. #5
    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?
    We're a Kingdom, and we're United!!

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Dowsey1977
    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

  7. #7
    Many thanks for all your help!
    We're a Kingdom, and we're United!!

  8. #8
    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!
    We're a Kingdom, and we're United!!

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Quote Originally Posted by Dowsey1977
    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
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •