Results 1 to 4 of 4

Thread: Using VB code to change form values.

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    2

    Question Using VB code to change form values.

    Im doing a spreadsheet for my A Level ICT coursework and have multiple sheets that are hidden from view unless a password is entered (all other routes to unhiding sheets are locked out). At the moment the password can only be changed if a user changes it in the Visual BASIC editor.
    VB Code:
    1. Private Sub ok_Click()
    2.   If password = chngpass.key Then
    3.       Unload Me
    4.       Correct.Show
    5.       ActiveWorkbook.Unprotect
    6.       Sheets("PaySlips").Visible = True
    7.       Sheets("Shifts").Visible = True
    8.       Sheets("Shifts").Select
    9.       Application.DisplayFormulaBar = True
    10.       Application.ActiveWindow.DisplayWorkbookTabs = True
    11.   Else
    12.       Unload Me
    13.       wrong.Show
    14.   End If
    15. End Sub
    As you can see, the password is stored on a different form (chngpass) I wish to use this form to enable the "admin" to change the password without the hassle of the VB editor. I have used "Nested If" statements (if thats what they are called in VB) to validate the original password and the new/repeated passwords before allowing any change, the only problem that I am unable to work around is permenantly changing the value of the text box that the password is stored in, as it just resets when it closes. Can someone help me by sending a line of code that will work around this problem if it exists?
    Thanks in advance,

    Craig.

  2. #2
    Junior Member
    Join Date
    Jul 2004
    Posts
    29

    Re: Using VB code to change form values.

    I'm not sure what you mean when you say it just resets.....do you mean the new password isn't being saved??

    If so, then you might try this:
    Activeworkbook.save

    (Just guessing)

    Also, I got a question for you? How do you lock out a hidden sheet? The user can't go to Format/Sheet/Unhide to view the hidden sheet? Please let me know how because I could use that trick.

    Thanks.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    2

    Re: Using VB code to change form values.

    I put this code into a user form that runs when the workbook loads up, it simply disables the "Format" menu.
    VB Code:
    1. Application.CommandBars("Format").Enabled = False
    The "Format" can be changed to match any of the menu buttons except for "Insert" and I'm unsure if it can be locked out at all.

    I also put this code in to stop users gaining access to the Visual BASIC Editor by right clicking on the sheet tabs and selecting "View Code".
    VB Code:
    1. Application.ActiveWindow.DisplayWorkbookTabs = False

  4. #4
    New Member
    Join Date
    Apr 2005
    Posts
    1

    Re: Using VB code to change form values.

    Set newSheet = Worksheets.Add
    newSheet.Visible = xlVeryHidden

    will hide a sheet from the format view, I have used it to hide a user sheet from all users except admins.

    I hope this helps

    "There are 10 kinds of people in the world, those that understand binary and those that don't"

Posting Permissions

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



Click Here to Expand Forum to Full Width