can't move the focus to the control (1 Viewer)

Bee

Registered User.
Local time
Today, 13:43
Joined
Aug 1, 2006
Messages
487
Hi

I am trying to write simple code that undoes entering a new record and moves the focus to a mandatory field. I wrote the code below; however, I get this run time error message each time I run it.

DB can't move the focus to the control PlotNum.

My code:
Code:
Private Sub cmbHouseType_BeforeUpdate(Cancel As Integer)
    Forms![frmHouse]![qryHouse2]![PlotNum].SetFocus
    If Forms![frmHouse]![qryHouse2]![PlotNum].Text = "" Then
        Cancel = True
        Me.Undo
        MsgBox "Please enter the Plot Number first, then enter the House Type"
    End If
End Sub

Any help will be very much appreciated
B
 

Zigzag

Registered User.
Local time
Today, 13:43
Joined
Aug 19, 2007
Messages
386
If it is on the same form and not a subform try using

DoCmd.GoToControl "PlotNum"

Garry
 

Zigzag

Registered User.
Local time
Today, 13:43
Joined
Aug 19, 2007
Messages
386
I wanted to check it would work before posting....

If it is a subform then, goto the subform first then the control,

DoCmd.GoToControl ("qryHouse2")
DoCmd.GoToControl ("PlotNum")

Garry
 

Bee

Registered User.
Local time
Today, 13:43
Joined
Aug 1, 2006
Messages
487
That worked fine - cheers.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:43
Joined
Feb 19, 2002
Messages
43,768
You can refer to form controls with - Me. - this method has the advantage of giving you intellisense. And, FYI, the .text property is ONLY available when the control has the focus. Unless you specifically want the .text property, the normal reference would be to .value which is also the default property.
 

Users who are viewing this thread

Top Bottom