Set Focus (1 Viewer)

D

D B Lawson

Guest
Why is this not returning the focus to the Title text box when the message box is cancelled? It worked in '97 but is not in 2000:

Private Sub Title_Exit(Cancel As Integer)
If IsNull([Title]) Then
MsgBox "You must enter Mr/Mrs/Miss etc"
End If
If IsNull(Title) Then
Me.Title.SetFocus
End If
End Sub
 

KMAN

New member
Local time
Today, 08:55
Joined
May 2, 2000
Messages
8
Me.Title.SetFocus
... should be ...
Me!Title.SetFocus
 
D

D B Lawson

Guest
Tried Me!Title.SetFocus. Did not work. Any other suggestions to make sure user fills field before being allowed to move on?
 
R

Richie

Guest
Not sure about 2000 but I don't know why you use if twice might be worth trying this,
Private Sub Title_Exit(Cancel As Integer)
If IsNull([Title]) Then
MsgBox "You must enter Mr/Mrs/Miss etc" vbOKOnly, ""
Me!Title.SetFocus
End If
End Sub
 

R. Hicks

AWF VIP
Local time
Today, 02:55
Joined
Dec 23, 1999
Messages
619
I'll take a stab at it.

Private Sub Title_Exit(Cancel As Integer)
If IsNull(Me![Title]) Then
MsgBox "You must enter Mr/Mrs/Miss etc"
Cancel = True
Me![Title].SetFocus
End If
End Sub

If this control has focus at the time of this event, you don't need the setfocus, the cancel will retain the cursor in this txtbox.

HTH
RDH

[This message has been edited by R. Hicks (edited 08-11-2000).]

[This message has been edited by R. Hicks (edited 08-11-2000).]

[This message has been edited by R. Hicks (edited 08-11-2000).]
 

Ron Bell

Registered User.
Local time
Today, 08:55
Joined
Jul 25, 2000
Messages
33
Hi : just to add some more -

I've had this one: - found only way to resolve is to set via another control ie:

In yr Title_Exit()
Me![secondcontrol].setfocus ' anything on form

Then in secondcontrols 'On Got Focus' event
Me![firstcontrol].SetFocus 'off it goes, back to first control

Note: this probably because you cannot set focus on a control which already has the focus!!!? - ie yr Title_Exit()

"R. Hicks" version is probably the most useable though!

[This message has been edited by Ron Bell (edited 08-13-2000).]
 
D

D B Lawson

Guest
Many thanks for all the suggestions. R Hicks' worked a treat.
 

Users who are viewing this thread

Top Bottom