SetFocus Problem

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
.
 
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.
 
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
 
Back
Top