SetFocus error

B

Blair

I have this code below and it was working. The line Text48.SetFocus was
doing what it should. But now when it exicutes it comes up with a Run-time
error 2110 it says that it can't move the focus to the control Text48. I
have checked and it's not a label, visible property is set to yes and enable
property is set to yes, so what else could have caused it to start doing
this. I know it is something I have done in the coding but I don't know what
to look for. Can anyone help
Thanks Blair

Private Sub Ctl1st_MATING_GotFocus()

[1st MATING] = DLookup("[MALE NUMBER]", "QFirstMatingMaleQuery")

MaleNumber = DLookup("[Male Number]", "98MaleHistory", "[Male Number] = '" &
[1st MATING] & "'")

If IsNull([1st MATING]) Then
Beep
MsgBox "No Male Number Please Check Nest #"
Text48.SetFocus
End If
 
T

TC

I'd try this. Immediately before the setfocus call, explicitly display
the relevant properties of the text48 control, just to be /certain/
that they are correct:

msgbox text48.visible & " " & text48.enabled

My guess is, you will find that the text48 is /not/ enabled. The msgbox
will show you for sure.

Three more comments:

(1) It is generally not good to do data validation from the GotFocus
event. The poor user hasn't had a chance to enter anything yet (into
that control)! You'd generally do data validation from the control's
AfterUpdate event. That event only fires when the user has actually
entered something into the field. And/or you could check in the form's
BeforeUpdate event, which fires before a whole updated record is
actually saved in the database.

(2) Similarly it is generally not a good idea to alter underlying
recordset fields (if [1st MATING] is one) from any events /except/ the
form-level before/after update/insert events. What if the user queries
a record, puts the cursor into the [1st MATING] field, then clicks the
close button w/out doing anything further? At this point, the record is
updated but not yet saved, so Access will ask the user whether he wants
to save the update or not. That's not good, cos the user hasn't done
anything that /needs/ to be saved, from his perspective.
 
B

Blair

I Have just got your post, so I will check it out.

One comment on my part
I don't know much most of what I do is cut and past and modify to get to
work. all help is appreciated. My whole db needs to be restructured tables
and all. but that will come later Unless some one out there is willing to
help me do it for a fair price.
Thanks for the help
 

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