Error handling

bhandari

Active Member
Joined
Oct 17, 2017
Messages
359
i have made a userform to log in ..if user types 3 times incorrect details ..
it must quit workbook

there is a issue with my file with the "start task manager" if they press quit Microsoft Excel.
before Quitting
it is asking save,dont save,cancel

if user press cancel button they can access my file WITHOUT LOG IN..any tips for this
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Re: need help with error handling

Firstly are you sure you want to Quit Excel? Is it possible that they will have other workbooks open? If so you could be interferring with their other work.

Either way you should close the Workbook. Something like:

Code:
Call Me.Close(SaveChanges:=False)

The above in ThisWorkbook module.

Hope this helps.
 
Upvote 0
Re: need help with error handling

Close my workbook only..i mean while he opened my project userform will pop up
it should be close if he attempted 3 times incorrect details
Code:
If Trial = 3 Then
msg = MsgBox("Wrong password, the form will close…", vbCritical + vbOKOnly, TitleStr)
ActiveWorkbook.Close True
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"
Call Me.Close(SaveChanges:=False)

is it will work? or any modification in it?
if there are 3 userforms in it is hould mention name of userform?(NAME:USRFRM1)

Code:
Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
'   Prevents use of the Close button
If CloseMode = vbFormControlMenu Then
MsgBox "Clicking the Close button does not work."
Cancel = True
End If
End Sub
 
Last edited:
Upvote 0
Re: need help with error handling

In your case I believe you should be using:

Rich (BB code):
ActiveWorkbook.Close(SaveChanges:=False)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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