Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SETFOCUS PROBLEM

Status
Not open for further replies.

lotje1234

Programmer
Nov 7, 2005
5
NL
Hi,

I don't know what's wrong about a simple piece of code.
I'm trying to set the focus back to a control when a user types a wrong value.

Private Sub KENTEKEN_AfterUpdate()
If IsNull(DLookup("[KENTEKEN]", "VRACHTWAGENS", "[KENTEKEN] = '" & Me.KENTEKEN & "'")) Then
Me.KENTEKEN.SetFocus
End If
End Sub

The program goes to the next control even when the data is not find by the Dlookup-method !!!
 
would it not be easier to use a drop down box and limit the entry to only the valid records?

--------------------
Procrastinate Now!
 
Thanks for your reply !

Yes, maybe but i wanna know why it doesn't work.
I need it also in another part of the program.
Any ideas ?
 
Does it work if you do it this way?
Code:
Private Sub KENTEKEN_AfterUpdate()
 If IsNull(DLookup("[KENTEKEN]", "VRACHTWAGENS", "[KENTEKEN] = '" & [COLOR=red]Me!KENTEKEN[/color] & "'")) Then
   [COLOR=red]Me!KENTEKEN.SetFocus[/color]
      End If
End Sub
 
Why not using the BeforeUpdate event procedure of KENTEKEN and play with the Cancel argument ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yes, it's an interesting behaviour. There's nothing wrong with your code.
Even if you leave only:
Private Sub KENTEKEN_AfterUpdate()
Me.KENTEKEN.SetFocus
End Sub
it will still not work.
If you set the focus on another control it works. Interesting...

Anyway, for your problem, use PHV's suggestion, much better on BeforeUpdate.
 
Perhaps it doesn't work on AfterUpdate() because your table is populated with data therefore your IsNull(Dlookup()) returns false.


~Melagan
______
"It's never too late to become what you might have been.
 
I'm sorry I didn't word that very well --- your AfterUpdate() event is triggered after your recordsource is updated.

Say a user enters "GO TEAM" in your Me!KENTEKEN control. The data is updated in your recordsource. AFTERUPDATE()
Code:
 If IsNull(DLookup("[KENTEKEN]", "VRACHTWAGENS", "[KENTEKEN] = '" & Me.KENTEKEN & "'")) Then
   Me.KENTEKEN.SetFocus
      End If

...will return false because your table was updated with "GO TEAM" before your event to test your table for that value was triggered.

~Melagan
______
"It's never too late to become what you might have been.
 
Melagan, you confuse the AfterUpdate event of the Form and the AfterUpdate event of the control ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
lotje1234 . . .

[blue]PHV[/blue] has already given you the best answer:

Switch to the [blue]BeforeUpdate[/blue] event & make use of the [blue]Cancel[/blue] arguement!

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top