run-time error '2110'

G

Guest

I am moving the focus to a text box but I get run-time error '2110':
Microsoft Office Access can't move the focus to the control 'txtRowNo', but I
can't see what's wrong.

txtEmpNo.SetFocus
If txtEmpNo.Text = "" Then
MsgBox ("Look Up Requires An Employee No. And A Row No.")
Exit Sub
End If
txtRowNo.SetFocus <---- This line is where it stops
If txtRowNo.Text = "" Then
MsgBox ("Look Up Requires An Employee No. And A Row No.")
Exit Sub
 
G

Guest

I'm not certain why you're getting the error message but it is unnecessary to
SetFocus to a control in order to check its value. Try the following:
If Me!txtEmpNo.Text = "" Then
MsgBox ("Look Up Requires An Employee No. And A Row No.")
Exit Sub
End If
If Me!txtRowNo.Text = "" Then
MsgBox ("Look Up Requires An Employee No. And A Row No.")
Exit Sub
End If

The code above assumes it is running in an event associated with the same
form that contains the controls. That's what makes "Me" valid. If your code
is outside of the form then the reference would be something like:
If Forms!YourFormName!txtRowNo.Text = "" Then

TomU
 
M

Marshall Barton

Lee Barden said:
I am moving the focus to a text box but I get run-time error '2110':
Microsoft Office Access can't move the focus to the control 'txtRowNo', but I
can't see what's wrong.

txtEmpNo.SetFocus
If txtEmpNo.Text = "" Then
MsgBox ("Look Up Requires An Employee No. And A Row No.")
Exit Sub
End If
txtRowNo.SetFocus <---- This line is where it stops
If txtRowNo.Text = "" Then
MsgBox ("Look Up Requires An Employee No. And A Row No.")
Exit Sub


Tom put his finger on your problem, but the code he posted
is still using the Text property. Unlike the VB controls,
Access controls use the Value property, but, since it's the
default property, you don't even need to specify it. It
might be a good idea to specify the object that the controls
are a member of though.

If Me.txtEmpNo = "" Then
MsgBox ("Look Up Requires An Employee No. And A Row
No.")
Exit Sub
End If
If Me.txtRowNo = "" Then
MsgBox ("Look Up Requires An Employee No. And A Row
No.")
Exit Sub
 

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

Top