Full Version: Set Focus Problem
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
dashiellx2000
I'm pulling my hair out over this, but can anyone tell me why my set focus command isn't working?

QUOTE
If Me.DateOfService >= Date Then
MsgBox "The Service Date Must be less then today's date!", vbCritical, "DateError"
Me.DateOfService = Null
[Forms]![frmMARefundEntry]![DateOfService].SetFocus
End If


I originally tried just he Me.DateOfService.SetFocus, but that didn't work so I tried the full identification.

Thanks.
fkegley
I would try this:

CODE
If CDate(Me.DateOfService) >= Date() Then
MsgBox "The Service Date Must be less then today's date!", vbCritical, "DateError"
Me.DateOfService = Null
[Forms]![frmMARefundEntry]![DateOfService].SetFocus
End If
dashiellx2000
Thanks Frank. But that didn't work.

One think I know my version of A97 does is when I type Date() in VBA it changes it to Date. Would this have anything to do with it???

Thanks.
fkegley
If it is doing it itself, then that is not the problem.

Have you tried setting a break point and stepping through the code?

Just in case, open the code window, and click in the gray area to the left of the first line of the troubled procedure. You should see a brown red symbol. Then close the code window and switch to Form View. Do what you have to do to cause this code to go off. It should open the code window. The line about to be executed will be highlighted yellow. Press F8 to move through the lines. Rest the mouse pointer on the Me.DateOfService to see what it thinks is there.
narbspot
Suggestion- DateOfService isn't locked when you set the focus is it?. Also, Maybe the form is corrupt, just copy everything to a new one and see if that works. I honestly don't know what is causing the focus to not be set. Does Access not like the code or does it not set the focus?
dashiellx2000
Thanks Frank and Narb, but I just can't figure this out. The code does everything, but set the focus on the field. And it is only in this instance. I have other set focus commands on the form and they all work fine. I'm at a loss. I just made the field required so if they don't go back and manually enter it, when they attempt to close the form or goto a new record they have to go enter it.

Thanks.
fkegley
William, I too am having trouble with why this is not working. I have noticed several times in my career that sometimes stuff just happens! You just have to work around it the best way you can.
rkeifer
Where is this code ? What event ?
dashiellx2000
It is on the after update event.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.