Results 1 to 12 of 12

Thread: Run-time error "438"

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,888
    Location
    1. I added Option Explicit and when I complied (Alt-D) I got "Variable Not Defined" on the User1 line

    Option Explicit
    
    Dim bOK2Use As Boolean
    Private Sub btnOK_Click()
        Dim bError As Boolean
        Dim sSName As String
        Dim p As DocumentProperty
        Dim bSetIt As Boolean
        bOK2Use = False
        bError = True
        If Len(txtUser.Text) > 0 And Len(txtPass.Text) > 0 Then
            bError = False
            Select Case txtUser.Text
                Case "User1"
                    sSName = "u1sheet"
                    If txtPass.Text <> "u1pass" Then bError = True
                Case "User2"
                    sSName = "u2sheet"
                    If txtPass.Text <> "u2pass" Then bError = True
                Case Else
                    bError = True
            End Select
        End If
        If bError Then
            MsgBox "Invalid User Name or Password"
        Else
            'Set document property
            bSetIt = False
            For Each p In ActiveWorkbook.CustomDocumentProperties
                If p.Name = "auth" Then
                    p.Value = sSName
                    bSetIt = True
                    Exit For
                End If
            Next p
            If Not bSetIt Then
                ActiveWorkbook.CustomDocumentProperties.Add _
                  Name:="auth", LinkToContent:=False, _
                  Type:=msoPropertyTypeString, Value:=sSName
                   
        End If
       
            Sheet1(User1).Visible = True
            Sheet2(User2).Unprotect (txtPass.Text)
            Sheet3(User3).Activate
            bOK2Use = True
            Unload UserForm1
        
        End If
        
    End Sub
    Private Sub UserForm_Terminate()
        If Not bOK2Use Then
            ActiveWorkbook.Close (False)
        End If
    End Sub


    2. 'Sheet1' is the Code Name for that sheet. It can also have a .Name like on the tabs at the bottom of the grid. I'm not sure about the User1, User2, and User3 so I can't suggest anything more specific

            Sheet1(User1).Visible = True
            Sheet2(User2).Unprotect (txtPass.Text)
            Sheet3(User3).Activate

    The way to refer to worksheets is like one of these

    Dim User1 as String
    
    Sheet1.Visible = True
    Worksheets ("User1").Visible = True
    
    User1 = "User1"
    Worksheets (User1).Visible = True

    3. I'm guessing you intended

            Worksheets("User1").Visible = True
            Worksheets("User2").Unprotect (txtPass.Text)
            Worksheets("User3").Activate
    but when I try to run it further, I get a "1004 unable to set the visible property of the worksheet class" so maybe the sample is corrupted
    Last edited by Paul_Hossler; 05-04-2018 at 02:35 PM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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