Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Blokeyfella
 
Posts: n/a
Default Password redundant through use of cancel

I have written an application that uses passwords to prevent unauthorised
users from changing data. This functions in the normal way i.e. by displaying
an input box for the password with OK and Cancel buttons.

When no password or an incorrect password is entered, an error message is
displayed on screen (msgbox "Incorrect. Please check caps lock is off and try
again"). However when Cancel is selected, rather than show this error
message, the macro ticks through as though the correct password has been
entered.

This is doubly frustrating as another application I have written does all of
the above but when cancel is pressed, pulls up the error message (as
required).

I have included the necessary code below, the version is MS Excel 2000.

PLEASE help me to understand why one of my applications is operating
differently (and wrongly) to the other. Thanks.

The code:

Windows("Training Log.xls").Activate
Application.ScreenUpdating = False
Sheets("Menu").Select
On Error GoTo TPassword_Err
ActiveSheet.Unprotect
Range("A1").Select
Sheets("AddTraining").Visible = True
Sheets("Menu").Visible = False
Sheets("AddTraining").Select
Application.ScreenUpdating = True
Range("C26").Select
Exit Sub
TPassword_Err:
MsgBox "Password Incorrect." & vbCrLf & vbCrLf _
& "Please check caps lock is off. Click on the Continue button to try
again"
Application.ScreenUpdating = True

end sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
JE McGimpsey
 
Posts: n/a
Default Password redundant through use of cancel

You haven't "included the necessary code" since you didn't include the
code in which the user inputs the password.

Just guessing, therefore, but one way might be:

Const sMSG = "Password Incorrect." & vbNewLine & vbNewLine & _
"Please check caps lock is off. Click Retry to try again."
Dim vResponse As Variant
Dim nButton As Long
Application.ScreenUpdating = False
With Workbooks("Training Log.xls").Worksheets("Menu")
Do
vResponse = Application.InputBox( _
Prompt:="Input Password:", _
Title:="Password", _
Default:="", _
Type:=2)
If vResponse = False Then Exit Sub 'User cancelled
On Error Resume Next
.Unprotect Password:=vResponse
On Error GoTo 0
If .ProtectContents Then
nButton = MsgBox(sMSG, Buttons:=vbRetryCancel)
If nButton = vbCancel Then Exit Sub
End If
Loop Until .ProtectContents = False
.Visible = True
Application.Goto .Range("A1"), Scroll:=True
With .Parent.Sheets("AddTraining")
.Visible = True
Application.Goto .Range("C26"), Scroll:=False
End With
End With
Application.ScreenUpdating = True



In article ,
"Blokeyfella" wrote:

I have written an application that uses passwords to prevent unauthorised
users from changing data. This functions in the normal way i.e. by displaying
an input box for the password with OK and Cancel buttons.

When no password or an incorrect password is entered, an error message is
displayed on screen (msgbox "Incorrect. Please check caps lock is off and try
again"). However when Cancel is selected, rather than show this error
message, the macro ticks through as though the correct password has been
entered.

This is doubly frustrating as another application I have written does all of
the above but when cancel is pressed, pulls up the error message (as
required).

I have included the necessary code below, the version is MS Excel 2000.

PLEASE help me to understand why one of my applications is operating
differently (and wrongly) to the other. Thanks.

The code:

Windows("Training Log.xls").Activate
Application.ScreenUpdating = False
Sheets("Menu").Select
On Error GoTo TPassword_Err
ActiveSheet.Unprotect
Range("A1").Select
Sheets("AddTraining").Visible = True
Sheets("Menu").Visible = False
Sheets("AddTraining").Select
Application.ScreenUpdating = True
Range("C26").Select
Exit Sub
TPassword_Err:
MsgBox "Password Incorrect." & vbCrLf & vbCrLf _
& "Please check caps lock is off. Click on the Continue button to try
again"
Application.ScreenUpdating = True

end sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Protect Workbook vs Worksheet?? Dan B Excel Worksheet Functions 3 November 7th 05 09:02 PM
Rogue Password on Properties and References ExcelMonkey Excel Discussion (Misc queries) 0 October 5th 05 01:16 PM
Password Issue keithl816 Excel Discussion (Misc queries) 6 July 10th 05 06:20 PM
Import Data Keeps asking for Password Dominator Excel Discussion (Misc queries) 0 June 5th 05 11:25 PM
Password cannot be removed twa14 Excel Discussion (Misc queries) 3 December 14th 04 11:27 AM


All times are GMT +1. The time now is 05:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"