Hi All,
I have a problem on a username password login form. I use:
txtPassword.Tex t = StrConv(txtPass word.Text, vbProperCase) to validate the
proper case when someone enters their name and password. It work when you
use the button to continue, but if you hit enter on your keyboard the event
apparently doesnt lose focus and it says you entered the wrong password. Is
there an easy fix for this. I pointed out the problem code below. Any help
would be appreciated.
Thanks,
Kelsey
Option Explicit
Public LoginSucceeded As Boolean
Private Sub cmdCancel_Click ()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim db As Database
Dim rs As DAO.Recordset
Set db = OpenDatabase(Ap p.Path & "\testlogin.mdb ")
Set rs = db.OpenRecordse t("login")
Do While Not rs.EOF
If txtUserName.Tex t = "Guest" And txtPassword.Tex t = "Guest" Then
Guest.Show
Exit Sub
End If
If rs.Fields("user name") = (txtUserName.Te xt) And _
rs.Fields("pass word") = (txtPassword.Te xt) Then
Form1.Show
Unload Me
Exit Sub
Else
rs.MoveNext
End If
Loop
txtPassword.Tex t = ""
MsgBox "Incorrect Password!", vbCritical
End Sub
Private Sub txtPassword_Los tFocus() <--------Here
txtPassword.Tex t = StrConv(txtPass word.Text, vbProperCase)
End Sub
Private Sub txtUserName_Los tFocus()
txtUserName.Tex t = StrConv(txtUser Name.Text, vbProperCase)
End Sub
Private Sub frmLogin_Load()
Data1.DatabaseN ame = (App.Path & "\testlogin.mdb ")
Data1.RecordSou rce = "login"
End Sub 3 9430
Are the textboxes bound? Do you have any code behind the text boxes'
KeyPress event that you didn't show here? I ask because you said it throws
an invalid password when you press enter. The LostFocus event won't fire
until that control loses focus (who'd a thunk) when another control gets
focus.
If you wanted to, you can turn the enter key into a forward tab by
specifying which control to set focus to when the enter key is detected in
the textboxes' respective KeyPress events. Something like...
Private Sub txtUserName_Key Press(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0 ' bye bye beep
txtPassword.Set Focus
End If
End Sub
Private Sub txtPassword_Key Press(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0 ' bye bye beep
cmdOK.SetFocus
End If
End Sub
Or to simplify it, you can just do this in each KeyPress event...
If KeyAscii = 13 Then
KeyAscii = 0 ' bye bye beep
SendKeys "{TAB}"
End If
"Randi" <RS******@stny. rr.com> wrote in message
news:R9******** **********@twis ter.nyroc.rr.co m... Hi All, I have a problem on a username password login form. I use: txtPassword.Tex t = StrConv(txtPass word.Text, vbProperCase) to validate the proper case when someone enters their name and password. It work when you use the button to continue, but if you hit enter on your keyboard the
event apparently doesnt lose focus and it says you entered the wrong password.
Is there an easy fix for this. I pointed out the problem code below. Any
help would be appreciated.
Thanks, Kelsey
Option Explicit
Public LoginSucceeded As Boolean
Private Sub cmdCancel_Click () 'set the global var to false 'to denote a failed login LoginSucceeded = False Unload Me End Sub
Private Sub cmdOK_Click() Dim db As Database Dim rs As DAO.Recordset
Set db = OpenDatabase(Ap p.Path & "\testlogin.mdb ") Set rs = db.OpenRecordse t("login")
Do While Not rs.EOF If txtUserName.Tex t = "Guest" And txtPassword.Tex t = "Guest" Then Guest.Show Exit Sub End If If rs.Fields("user name") = (txtUserName.Te xt) And _ rs.Fields("pass word") = (txtPassword.Te xt) Then Form1.Show Unload Me Exit Sub Else rs.MoveNext End If Loop txtPassword.Tex t = "" MsgBox "Incorrect Password!", vbCritical End Sub Private Sub txtPassword_Los tFocus() <--------Here txtPassword.Tex t = StrConv(txtPass word.Text, vbProperCase) End Sub
Private Sub txtUserName_Los tFocus() txtUserName.Tex t = StrConv(txtUser Name.Text, vbProperCase) End Sub
Private Sub frmLogin_Load() Data1.DatabaseN ame = (App.Path & "\testlogin.mdb ") Data1.RecordSou rce = "login" End Sub
"Randi" <RS******@stny. rr.com> wrote in message news:<R9******* ***********@twi ster.nyroc.rr.c om>... Hi All, I have a problem on a username password login form. I use: txtPassword.Tex t = StrConv(txtPass word.Text, vbProperCase) to validate the proper case when someone enters their name and password. It work when you use the button to continue, but if you hit enter on your keyboard the event apparently doesnt lose focus and it says you entered the wrong password.
Neither the LostFocus nor Validate events are reliable IMO because
they do not fire consistently. Clicking toolbar buttons, menu items
and pressing enter to trigger the default command button are just a
few cases where they don't happen. You can use them for simple
validation if you want but never assume that they will run. In this
case, have the command button code do the StrConv.
"Bob Butler" <bu*******@eart hlink.net> wrote in message
news:fa******** *************** **@posting.goog le.com... "Randi" <RS******@stny. rr.com> wrote in message
news:<R9******* ***********@twi ster.nyroc.rr.c om>... Hi All, I have a problem on a username password login form. I use: txtPassword.Tex t = StrConv(txtPass word.Text, vbProperCase) to
validate the proper case when someone enters their name and password. It work
when you use the button to continue, but if you hit enter on your keyboard
the event apparently doesnt lose focus and it says you entered the wrong
password. Neither the LostFocus nor Validate events are reliable IMO because they do not fire consistently. Clicking toolbar buttons, menu items and pressing enter to trigger the default command button are just a few cases where they don't happen. You can use them for simple validation if you want but never assume that they will run. In this case, have the command button code do the StrConv.
I would say the events are reliable, but that controls don't lose focus
in some situations where you might expect them to. I agree that you
should never assume they will be fired, and always put required
processing in a procedure that will definitely run.
LostFocus doesn't fire here because in fact, the textbox never loses
focus. If the default button only popped up a message, focus would
return to the textbox, not the default command button. Similarly,
Validate doesn't fire because it only fires just before a possible loss
of focus.
In many cases, it makes sense that selecting a menu or toolbar button
does not change the focus. If I click the Paste button, for instance, I
appreciate the fact that the focus stays where it is, and the paste
occurs where I intended it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MJW |
last post by:
Is there a way for me to know if or which command button was just
clicked that triggers the LostFocus event for the current control on a
Form?
I have a form that has many types of users who each have their own set
of fields they can change. Therefore I use setfocus property in the
lostfocus event for some of the users to get from one control to
another. Since I am "directing traffic" with setfocus, the users are
unable to use the...
|
by: vooose |
last post by:
Does anyone know the difference between these two?
The doc for LostFocus says
'Occurs when the control loses focus.'
whereas for Leave it says
'Occurs when the input focus leaves the control'
The doc also states that for controls losing focus you should use Leave,
so I do. Another reason I used it is because comboBox.LostFocus event
|
by: Bernard Bourée |
last post by:
I have some TextBoxes created by code.
I want to write a procedure to handle the lost of focus of any of these
TextBox.
How should I do that ?
Thanks
--
|
by: Wayne Wengert |
last post by:
I have a form that has a cbo set to TabIndex 0 (it is the only item set to
tabindex 0). On page Load if I step through the code that cbo LostFocus
event fires after other initializations are completed and after the
LostFocus event completes, that cbo gets focus and the form opens? Why is
that LostFocus event firing? Any hints on how to debug this?
Wayne
|
by: Paul |
last post by:
I have a datagrid tied to a data adapter. Everything works great,
EXCEPT, the LostFocus event only fires when I click on a specific cell
within the DataGrid. If I set focus on another control, the LostFocus
event does not fire. This is causing problems because I am checking
for HasChanged on every CurrentCellChanged event.
So if I change a cell, move to a new row, the update occurs just fine.
However, if I change a cell, then set the...
| |
by: Scott McChesney |
last post by:
All -
I am in the process of developing a custom control that mimics the Office
2003 "Inbox" as closely as possible. After a great deal of frustrating work
trying to do a heavily custom-drawn ListView (which is how I believe MS is
doing it) and getting nowhere, I said "screw it" and built the thing from
scratch. I have a UserControl with a few contained controls, a header
control I'm drawing entirely by hand, and a Panel in which I'm...
|
by: Carmon |
last post by:
I am using Managed C++ with a CFormView and a MaskedTextBox and have used
MAKE_DELEGATE to sink the LostFocus event of this control.
I have other events I've sinked off this control and they all work fine,
however, the LostFocus does not fire.
I found Scribble online and they do the same thing I did, however, when I
used this code in Visual Studio 2005 the LostFocus event didn't get fired
either.
|
by: teddysnips |
last post by:
WINDOWS FORMS
I've a form that has a textbox that allows the user to enter a string.
On the LostFocus event, the textbox formats the string into a preferred
format.
However, if the user presses the "Save" button while the textbox has
the focus, the LostFocus code doesn't run at the right time, so that
the "Save" function is dealing with an incorrectly formatted string and
the whole caboodle goes splat.
|
by: dbuchanan |
last post by:
On the help page "TextBox Members" clearly there is an event for LostFocus.
It is inherited from control.
So without the event directly available for TextBox how do I use it?
I know I could create the event in code, but isn't there a more direct way?
|
by: kirk |
last post by:
I started with a System.Windows.Forms.Form and subscribed to its
LostFocus event. The event fires perfect.
I added a System.Windows.Forms.LinkLabel to the aforementioned Form
and tested the same LostFocus event again. It does not fire any
longer. If I remove the LinkLabel, LostFocus fires again.
Why does this fail and how can I get LostFocus to fire for the
container Form with a LinkLabel present?
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |