View Full Version : can't move the focus to the control


Bee
11-07-2007, 02:16 AM
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:
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
11-07-2007, 02:23 AM
If it is on the same form and not a subform try using

DoCmd.GoToControl "PlotNum"

Garry

Zigzag
11-07-2007, 02:35 AM
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
11-07-2007, 07:19 AM
That worked fine - cheers.

Pat Hartman
11-10-2007, 11:01 AM
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.