We have a school project which is to create a VBA through Excel and I have problem about coding attempts in Log in. Everytime I open the file and put some incorrect username and password once the message box appears and say that "You have entered an invalid username/password 3 times already" what would I do to make it 3 attempts? Thanks for the help.
CommandButtons
CANCEL
OK
TextBox
Username
Password
here is my code... - Private Sub CANCEL_Click()
-
-
If MsgBox("Are you sure you want to quit?", vbQuestion + vbYesNo, "Exit Program?") = vbYes Then
-
ThisWorkbook.Close 1
-
End
-
End If
-
-
End Sub
-
-
-
-
Private Sub OK_Click()
-
-
If Username.Text = "" Then
-
MsgBox "Please enter your username to proceed.", vbExclamation, "Missing Username"
-
Username.SetFocus
-
ElseIf Password.Text = "" Then
-
MsgBox "Please enter your password to proceed.", vbExclamation, "Missing Password"
-
Password.SetFocus
-
Else
-
-
If Username.Text = Sheet2.Cells("2", "B") And Password.Text = Sheet2.Cells("3", "B") Then
-
MsgBox "Correct username and password. Access Granted.", vbInformation, "Welcome to Merry Toddlers Learning Center"
-
Username.Text = ""
-
Password.Text = ""
-
'Application.DisplayFullScreen = True
-
Login.Hide
-
Welcome.Show 1
-
Else
-
MsgBox "Invalid username/password. Please try again.", vbCritical, "Invalid username/password"
-
Tries = Tries - 1
-
If Tries < 1 Then
-
MsgBox "You have entered an invalid username/password 3 times already. Program will now terminate.", vbCritical, "Program Shutdown"
-
ThisWorkbook.Close 1
-
End
-
End If
-
End If
-
-
End If
-
-
End Sub
-
-
Private Sub Password_Change()
-
-
End Sub
-
-
Private Sub UserForm_QueryClose(CANCEL As Integer, CloseMode As Integer)
-
CANCEL = 1
-
Call CANCEL_Click
-
End Sub
-
-
Private Sub Username_Change()
-
-
End Sub
3 4231 zmbd 5,501
Expert Mod 4TB
Hint Line 31
The variable is not initialized.
You should also get in to the habit of explicitly declaring your variables. Open any Office-word/excel/database>
<alt><F11> to open the VBA editor...
Menu>Tools>Options>
>Editor tab, UNCHECK "auto Syntax Check" you're vba code will still highlight if in error, just no annoying message boxes while you type!
>CHECK the "Require Variable Declaration" option --- you will now have to use the "DIM...variablename....typecaste" construct in your code. Highly advised.
Everything else on this tab check, I prefer the tab step to be either 2 or 4 spaces.
>The other tabs are good as is for most people, review if you want. FrenzKyleBernas
Please be aware of the fact that we do not normally answer homework questions; however, because you have made an effort and shown your work - we do often make an exception to the rule in such cases with a hint or two; however, rarely an outright answer. :)
I think using a global variable (integer type) , increasing it's value by 1 on each click of "Ok" button may help to create the logic while the variable is less than 3.
zmbd 5,501
Expert Mod 4TB
svh00987,
Unnecessary complication to the code.
OP simply needs to initialize the variable.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: c duden |
last post by:
Excel won't allow documents to be linked to a worksheet in office 2000 when
using C# to create an add-in.
The following code snippets are what was used in the attempts
(there are more...
|
by: Ange T |
last post by:
Hi there,
I'm having pain with the VB behind an Access form. The form is used to
create reports in Excel based on the details entered in the form. This
has always worked without error on my...
|
by: Mr. Smith |
last post by:
Hello all,
My code can successfully open, write to, format and save several
worksheets in a workbook then save it by a given name, close and quit excel.
My problem is that if I try and do it...
|
by: Mike Knight |
last post by:
(I've also posted this problem on microsoft.public.excel.programming)
I have a MS Access 2003 Database named "AS400 Fields.mdb". This
database contains links to tables on an AS400.
In MS...
|
by: Dent2 |
last post by:
I wrote a nice C# excel routine to automate the formatting of some raw CSV
data. I wrote the
routine on a WinXP computer with Visual Studio .NET 2003 and Office XP
installed. It compiled and ran...
|
by: Steve Chatham |
last post by:
I use the following code:
Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged
Dim sFile As String =...
|
by: Steve |
last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains
custom functions. I believe I need to use COM interop to allow VBA code in
Excel 2002 to access it. I've studied...
|
by: =?Utf-8?B?c2NobWlkdGU=?= |
last post by:
Hi
How can I Export an HTML Table to excel?
My goal is a button, and when the user clicks this button a popup appears
asking the user to 'open' or 'save' the generated Excel file.
Actually...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |