issue with macro

bhandari

Active Member
Joined
Oct 17, 2017
Messages
359
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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
1004 means the directory is not found in general, so something is not quite right, might be a space or backslash
 
Upvote 0
1004 means the directory is not found in general, so something is not quite right, might be a space or backslash

can we do bypass for it, i don't know where to change space or backslash
can you please figure it out in my code

This error only pop up and getting yellow color here.Especially when i am changing folder path or rename my file
Code:
Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
'   Prevents use of the Close button
If CloseMode = vbFormControlMenu Then
[COLOR="#FF8C00"]ActiveWorkbook.Close savechanges:=False[/COLOR]
Else
MsgBox "Welcome to Quantitys World"
End If
End Sub
 
Upvote 0
the highlight part looks fine to me, what I don't understand is the line before closemode is to be a number, is vbformcontrolmenu also a number
 
Upvote 0
Cross-posted: https://www.excelforum.com/excel-pr...19-iam-getting-vba-error1004.html#post4811549

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here: http://www.mrexcel.com/forum/board-announcements/99490-forum-rules.html).

This way, other members can see what has already been done in regard to a question, and do not waste time working on a question that may already be answered.

For a more complete explanation on cross-posting, see here: http://www.excelguru.ca/content.php?184).
 
Upvote 0

Forum statistics

Threads
1,214,825
Messages
6,121,787
Members
449,049
Latest member
greyangel23

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