Results 1 to 3 of 3

Thread: iam getting Vba erro1004

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    1
    Rep Power
    0

    iam getting Vba erro1004

    Code:
    Option Explicit
    Private Trial As Long
    Code:
    Private Sub cmdCheck_Click()
    'Declare the variables
    Dim AddData As Range
    Dim user As Variant
    Dim Code As Variant
    Dim result As Integer
    Dim TitleStr As String
    Dim Current As Range
    Dim PName As Variant
    Dim msg As VbMsgBoxResult
    
    'Variables
    user = Me.TxtUser.Value
    Code = Me.TxtPass.Value
    TitleStr = "Password check"
    result = 0
    Set Current = Sheet6.Range("K2")
    'Error handler
    On Error GoTo errHandler:
    'Destination location for login storage
    Set AddData = Sheet6.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
    'Check the login and passcode for the administrator
    If user = "Hardy Cross" And Code = 8118425 Then
    MsgBox "Welcome Back: –   " & user & vbCrLf _
    & " You have admistrator priviledges" & vbCrLf _
    & " I will open the control panel for you"
    'record user login
    AddData.Value = user
    AddData.Offset(0, 1).Value = Now
    'send the username to the worksheet
    Current.Value = user
    'unoad this form
    Unload Me
    'Show navigation form
    UserForm1.Show
    'End the procedure if conditions are meet
    Exit Sub
    End If
    'Check the login and passcode for the administrator
    If user = "popup" And Code = "Local" Then
    MsgBox "Welcome: –   " & user & "  " & Code & vbCrLf
    'record user login
    AddData.Value = user
    AddData.Offset(0, 1).Value = Now
    'send the username to the worksheet
    Current.Value = user
    'unoad this form
    Unload Me
    'Show navigation form
    UserForm1.Show
    'End the procedure if conditions are meet
    Exit Sub
    End If
    'Check the login and passcode for the administrator
    If user = "Anthony Hunt" And Code = 1142081 Then
    MsgBox "Welcome: –   " & user & "  " & Code & vbCrLf
    'record user login
    AddData.Value = user
    AddData.Offset(0, 1).Value = Now
    'send the username to the worksheet
    Current.Value = user
    'unoad this form
    Unload Me
    'Show navigation form
    UserForm1.Show
    'End the procedure if conditions are meet
    Exit Sub
    End If
    'Check the login and passcode for the administrator
    If user = "Ove Arup" And Code = 1182116 Then
    MsgBox "Welcome: –   " & user & "  " & Code & vbCrLf
    'record user login
    AddData.Value = user
    AddData.Offset(0, 1).Value = Now
    'send the username to the worksheet
    Current.Value = user
    'unoad this form
    Unload Me
    'Show navigation form
    UserForm1.Show
    'End the procedure if conditions are meet
    Exit Sub
    End If
    'Check user login with loop
    If user <> "" And Code <> "" Then
    For Each PName In Sheet6.Range("H2:H100")
    'If PName = Code Then 'Use this for passcode text
    If PName = CInt(Code) And PName.Offset(0, -1) = user Then ' Use this for passcode numbers only
    MsgBox "Welcome Back: –   " & user & "   " & Code
    'record user login
    AddData.Value = user
    AddData.Offset(0, 1).Value = Now
    'Change variable if the condition is meet
    result = 1
    'Add usernmae to the worksheet
    Current.Value = user
    'Unload the form
    Unload Me
    'Show the navigation form
    
    Exit Sub
    End If
    Next PName
    End If
    ' Next UName
    'Check to see if an error occurred
    If result = 0 Then
    'Increment error variable
    Trial = Trial + 1
    'Less then 3 error message
    If Trial < 3 Then msg = MsgBox("Wrong password, please try again", vbExclamation + vbOKOnly, TitleStr)
    Me.TxtUser.SetFocus
    'Last chance and close the workbook
    If Trial = 3 Then
    msg = MsgBox("Wrong password, the form will close…", vbCritical + vbOKOnly, TitleStr)
    ActiveWorkbook.Close savechanges:=False
    
    End If
    End If
    Exit Sub
    'Error block
    errHandler:
    MsgBox "An Error has Occurred  " & vbCrLf & "The error number is:  " _
    & Err.Number & vbCrLf & Err.Description & vbCrLf & _
    "Please notify the administrator"
    
    
    End Sub
    Code:
    Private Sub UserForm_QueryClose _
    (Cancel As Integer, CloseMode As Integer)
    '   Prevents use of the Close button
    If CloseMode = vbFormControlMenu Then
    Application.ActiveWorkbook.Close savechanges:=False
    Else
    MsgBox "Welcome"
    End If
    End Sub
    iam getting 1004 error if i change file directory of folder name can any one fix this macro

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,341
    Rep Power
    10
    Hi bhandari

    You haven't mentioned which line you get the error.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,341
    Rep Power
    10
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Posting Permissions

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