Results 1 to 9 of 9

Not Sure how to point my code to the workbook that needs to open

Threaded View

  1. #1
    Registered User
    Join Date
    09-03-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    14

    Thumbs down Not Sure how to point my code to the workbook that needs to open

    This is the code for a user to log on with password, My question is after the user successful enter password, how do I get the code below to open up a certain name spreadsheet.

    The spread sheet name is CASA 212 INVENTORY, that needs to open after a successful login?


    Dim Trys As Integer
    
    Private Sub CommandButton1_Click()
    
       SUMBIT BUTTON
      
        Dim FoundIt As Range
        Dim Pwd     As String
        Dim Rng     As Range
        Dim Role    As String
        Dim User    As String
        Dim Wks     As Worksheet
        
            Set Wks = Sheet2
            Set Rng = Wks.Range("A1").CurrentRegion
            
                User = NameTextBox.Value
                If User = "" Then
                    MsgBox "Please Enter a User ID."
                    NameTextBox.SetFocus
                    Exit Sub
                End If
                
                Set Rng = Intersect(Rng, Rng.Offset(1, 0))
                
                Set FoundIt = Rng.Find(User, , xlValues, xlWhole, xlByRows, xlNext, False, False, False)
                If FoundIt Is Nothing Then
                    MsgBox "The User '" & User & "' was Not Found in the Access List.", vbExclamation
                    Exit Sub
                End If
                
                Pwd = FoundIt.Offset(0, 1)
                If pwdTextBox = "" Then
                    MsgBox "Please Enter a Password."
                    pwdTextBox.SetFocus
                    Exit Sub
                End If
                
                If pwdTextBox.Value <> Pwd Then
                    Trys = Trys - 1
                    If Trys = 0 Then
                        Unload Me
                        Exit Sub
                    End If
                    
                    MsgBox "You have Entered an Invalid Password." & vbCrLf _
                            & "Passwords are case sensitive. Check that the Caps Lock key is not set." & vbCrLf _
                            & vbCrLf & "You have " & Trys & " attempts to login left.", vbExclamation
                            
                    pwdTextBox.SelStart = 0
                    pwdTextBox.SelLength = Len(pwdTextBox)
                    pwdTextBox.SetFocus
                    Exit Sub
                End If
                       
                       
                For Each Opt In Frame1.Controls
                    If Opt.Value = True And Opt.Caption = FoundIt.Offset(0, 2) Then
                        Role = Opt.Caption
                        Exit For
                    Else
                        Role = "no match"
                    End If
                Next Opt
                
                If Role = "" Then
                    MsgBox "Please Select your Role."
                    Exit Sub
                End If
                
                If Role = "no match" Then
                    MsgBox " Your Role Does Not Match Your Profile.", vbExclamation
                    Exit Sub
                End If
        
            MsgBox "You have sucessfully Logged In."
            Unload Me
            
    End Sub
    
    Private Sub UserForm_Initialize()
    
      ' Number of log in attempts allowed.
        Trys = 5
        
      ' Empty NameTextBox
        NameTextBox.Value = ""
      ' Set length to NameTextBox
        NameTextBox.MaxLength = 6
    
      ' Empty pwdTextBox
        pwdTextBox.Value = ""
        
      ' Set pwdTextBox Char
        pwdTextBox.PasswordChar = "*"
    
      ' Empty Option Buttons
        tlOptionButton1.Value = False
        tmOptionButton2.Value = False
        sdmOptionButton3.Value = False
        dgmOptionButton4.Value = False
        gmOptionButton5.Value = False
    
      ' Set Focus on NameTextBox
        NameTextBox.SetFocus
        
    End Sub
    Attached Files Attached Files
    Last edited by jcfox6550; 09-10-2014 at 09:59 AM. Reason: Add Tags around code

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA code in existing code to open when workbook encrypt with password.
    By deo_y in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2014, 07:08 AM
  2. Help! VBA code to open workbook and populate with data from previous workbook
    By musicman1985 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-20-2014, 11:46 AM
  3. Code to open a workbook, do what i want, close it, and open the next
    By stuartsjg in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-30-2010, 05:43 PM
  4. Code to open a workbook , copy info and return it to another workbook using a cell v.
    By england79m in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-31-2008, 11:22 AM
  5. [SOLVED] Need VB code for workbook open to open a link
    By Daniel Baker in forum Excel General
    Replies: 2
    Last Post: 08-17-2006, 08:35 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1