Runtime 424 Error - object required

Heindrich8121

New Member
Joined
Mar 20, 2016
Messages
4
Hi
I am new to VBA. I cant find the problem in this vba coding:

Private Trial As Long
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 = Sheet2.Range("K2")
'Error handler
On Error GoTo errHandler:
'Destination location for login storage
Set AddData = Sheet2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
'Check the login and passcode for the administrator
If user <> "" And Code <> "" Then
MsgBox "Welcome Back: – " & user & " " & vbCrLf _
& " You have administrator 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
frmSetup.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 Sheet2.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 & ""
'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
frmNavigation.Show
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 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


please help solving the run time 424 error.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi welcome to the board.

It would be helpful if you could highlight which line of your code gives the error.

Also, I am a little puzzled with first part of your code below, it would seem so long as the two variables “user” and “code” have a value, then you will pass as an administrator – there appears to be no validation check of these values?

Rich (BB code):
 'Variables    user = Me.TxtUser.Value
    Code = Me.TxtPass.Value
    TitleStr = "Password check"
    result = 0
    
    Set Current = Sheet2.Range("K2")
    'Error handler
    On Error GoTo errHandler:
    'Destination location for login storage
    Set AddData = Sheet2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
    'Check the login and passcode for the administrator
    If user <> "" And Code <> "" Then
        MsgBox "Welcome Back: – " & user & " " & vbCrLf _
             & " You have administrator 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
        frmSetup.Show
        'End the procedure if conditions are meet
        Exit Sub
    End If

Dave
 
Upvote 0
Where in the code does the 424 error occur? Without the full set up of your workbook with all the correctly named sheets, userforms, ranges etc. it'll be very difficult to guess where and why the error occurred. You are likely to be missing something you hope will be there and it's not hence 424 - Object Required.
 
Upvote 0
hi

the code is linked to an administrator sheet where the users / administrators are loaded.

I cant tell you where the problem lies as the debugger doesnt show this
 
Upvote 0
hi

the code is linked to an administrator sheet where the users / administrators are loaded.

I cant tell you where the problem lies as the debugger doesnt show this
 
Upvote 0
hi

the code is linked to an administrator sheet where the users / administrators are loaded.

I cant tell you where the problem lies as the debugger doesnt show this

As already stated by another, “Without the full set up of your workbook with all the correctly named sheets, userforms, ranges etc. it'll be very difficult to guess where and why the error occurred.”

I note that the code you are using comes from here:Excel Userform Login - Multiple Level - Plus +++ - Online PC Learning

I would suggest that you contact the author Trevor Easton at the site who appears to provide online support for his project.

Dave.
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top