SetFocus Problem

G

Guest

SetFocus not working. See code below:

'test for valid password
Dim strValidPassWord As Integer
strValidPassWord = DCount("*", "tblOperators", "[PassWord] ='" &
PassWordLookUp] & "'")

If strValidPassWord = 0 Then
MsgBox "Must Enter Valid Password"
PassWordLookUp = ""

PassWordLookUp.SetFocus

Exit Sub
End If

If the user password not found after DlookUp() clear password text and
return focus back. Instead to focus goes to the next tab order text box.

Help Please
Thank you
 
G

Guest

hi,
if you are in the text box "PassWordLookup" then you
already have focus and for some reason vb wont let you set
focus to what already has focus.
in the text box the focus shifts to you need to put
something in it's before update event like
if isnull(me.passwordlookup) then
me.psswordlookup.setfocus
end if
this will shift focus back to the passwordlookup.
-----Original Message-----
SetFocus not working. See code below:

'test for valid password
Dim strValidPassWord As Integer
strValidPassWord = DCount
("*", "tblOperators", "[PassWord] ='" &
PassWordLookUp] & "'")

If strValidPassWord = 0 Then
MsgBox "Must Enter Valid Password"
PassWordLookUp = ""

PassWordLookUp.SetFocus

Exit Sub
End If

If the user password not found after DlookUp() clear password text and
return focus back. Instead to focus goes to the next tab order text box.

Help Please
Thank you
.
 
F

fredg

SetFocus not working. See code below:

'test for valid password
Dim strValidPassWord As Integer
strValidPassWord = DCount("*", "tblOperators", "[PassWord] ='" &
PassWordLookUp] & "'")

If strValidPassWord = 0 Then
MsgBox "Must Enter Valid Password"
PassWordLookUp = ""

PassWordLookUp.SetFocus

Exit Sub
End If

If the user password not found after DlookUp() clear password text and
return focus back. Instead to focus goes to the next tab order text box.

Help Please
Thank you

if you place your code in the control's Before Update event, you can
use the code below, which I have simplified for you:

Private Sub YourControl_BeforeUpdate (Cancel as Integer)
' test for valid password
If DCount("*", "tblOperators", "[PassWord] ='" &
PassWordLookUp] & "'") = 0 Then
MsgBox "Must Enter Valid Password"
Cancel = True
End If

Exit Sub

Focus is returned to the same control.
 
T

Tim Ferguson

SetFocus not working.

I assume this is code running in the BeforeUpdate event. Think about the
order of events:

beforeupdate -> afterupdate -> exit -> enter(new control) -> etc

You can set the focus during the BeforeUpdate, but unless you prevent
Access continuing down the chain it'll get moved on later anyway. This is
what the Cancel argument is for: set it to True and the whole update and
move-focus chain will be aborted. You won't get AfterUpdate or Exit
events either.

As Fred said.


All the best


Tim F
 

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

Similar Threads

Password Tries 3
SplitFormDatasheet property 6
setfocus not working? 3
setfocus not working 3
Not stopping at text box 1
SetFocus problem 7
SetFocus 2
SetFocus after MsgBox vbOKOnly - Then Exit Sub 3

Top