Staying in the textbox for new input

  • Thread starter Thread starter elli
  • Start date Start date
E

elli

Hi! (Again:))...
Thank U all for yesterday's help!
Today towards new challanges...
I created a form to ask username and password.
And even managed to make it to work..
Some little fixation still needed and this is where I need Your help. Now
when user puts wrong username there's a message-box saying: User not found
and so on (in finnish though) and the wrong username is cleared from the
textbox. Then the So far so good...
Then the application jumps to the password section, insted of staying in the
Kayttaja- textbox to let the user correct his/hers typing.... So what is the
piece of code that my code needs to stay there?

Thanks -elli the menace-

Private Sub Kayttaja_LostFocus()
Dim con As Object
Dim rs As Object
Dim s_sql As String
Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
s_sql = "select * from Users where Kayttaja='" & Trim(Kayttaja) & "'"
rs.Open s_sql, con, 1
If rs.EOF = True Then
MsgBox "Käyttäjää ei löydy"
Me.Kayttaja = ""
Else
apupw = rs!Salasana
End If
End Sub
 
Elli,
The best place for your code would be in the BeforeUpdate event of your
password text control.
The BeforeUpdate event is a "cancelable" procedure, so...
(Assuming Kayttaja is a bound field)

Private Sub Kayttaja_BEFOREUPDATE(Cancel as Integer) ' <****
Dim con As Object
Dim rs As Object
Dim s_sql As String
Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
s_sql = "select * from Users where Kayttaja='" & Trim(Kayttaja) & "'"
rs.Open s_sql, con, 1
If rs.EOF = True Then
MsgBox "Käyttäjää ei löydy"
Cancel = True
'<*****
Me.Kayttaja.Undo
'<*****
Else
apupw = rs!Salasana
End If
End Sub

If Kayttaja is an unbound field, just do the Cancel = True. The original
text
entry will remain, but be highlighted for over typing. That should be OK...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top