Code For DEL Excel File Workbook

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Option Explicit

Private Sub cmbValidate_Click()

Dim sPW As String, sUser As String

Dim sMsg As String, sTitle As String, sStyle As String

Dim iCounta As Integer

sUser = "Peter Arnett"

sPW = "Alison"

iCounta = Me.tbxGoes.Value 'set tbxUser visible prpety to false before using

sTitle = "Incorrect Password"

sMsg = "You have entered an incorrect Username or Password" _

& vbNewLine & "Try again" & vbNewLine & _

"You have " & (3 - iCounta) & " goes left"

sStyle = vbOKOnly + vbExclamation

If iCounta < 3 Then

If Me.tbxUser.Value <> sUser Or Me.tbxPW.Value <> sPW Then

MsgBox sMsg, sStyle, sTitle

With Me

tbxUser.Value = vbNullString

tbxPW = vbNullString

tbxUser.SetFocus

tbxGoes.Value = iCounta + 1

End With

Else
MsgBox "Correct Information Entered. Please Proceed.", vbOKOnly + vbInformation, "Correct
Information entered."

Sheet2.Activate

Unload Me

End If

ElseIf iCounta > 2 Then

MsgBox "You have tried three time incorrectly. WorkBook will be deleted!" _

, vbOKOnly + vbExclamation, "Warning"

With ActiveWorkbook

If .Path <> "" Then

.Saved = True

.ChangeFileAccess xlReadOnly

Kill ActiveWorkbook.FullName

End If

End With

Application.Quit

End If

End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()

Me.tbxGoes.Value = 1

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)


If CloseMode = 0 Then Cancel = True

MsgBox "Sorry, you must enter your password & username", vbExclamation, "Warning"

End Sub

Private Sub Workbook_Open()

frmPW.Show

End Sub

You might also like