Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become an Expert!

Join 244,310 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 863 people online right now. Registration is fast and FREE... Join Now!




Access 2003 problem setting focus on a ctl

 
Reply to this topicStart new topic

Access 2003 problem setting focus on a ctl

dogdays
1 Nov, 2007 - 06:51 AM
Post #1

New D.I.C Head
*

Joined: 7 Jun, 2007
Posts: 4


My Contributions
I have a form with 4 controls ctlA, ctlB, ctlC, ctlD
when I lose focus on ctlB i test to insure ctlB was populated,
if not I use a msgBox and then set ctlB to have focus.
Problem is focus shifts to ctlC, if I set focus on ctlD it works.

[code]

Private sub ctlB_lostfocus()
dim intResult as integer

if ctlB.Value = 0 then
intResult = MsgBox("CtlB must be filled in", vbOKCancel)
ctlB.setFocus
end if

End Sub
/code

tia


User is offlineProfile CardPM
+Quote Post


MRJ
RE: Access 2003 Problem Setting Focus On A Ctl
1 Nov, 2007 - 07:41 AM
Post #2

D.I.C Head
Group Icon

Joined: 13 Oct, 2007
Posts: 88



Thanked: 1 times
My Contributions
I think the problem is that when you make the call it has focus so it doesn't set it, it just moves on with the tab order. but if you set the focus to another field say ctlA then set it to ctlB it seems to work..

CODE


Private sub ctlB_lostfocus()
dim intResult as integer

if ctlB.Value = 0 then
intResult = MsgBox("CtlB must be filled in", vbOKCancel)

ctlA.setfocus  

ctlB.setFocus
end if

End Sub

User is offlineProfile CardPM
+Quote Post

MRJ
RE: Access 2003 Problem Setting Focus On A Ctl
1 Nov, 2007 - 09:12 AM
Post #3

D.I.C Head
Group Icon

Joined: 13 Oct, 2007
Posts: 88



Thanked: 1 times
My Contributions
Probably shouldn't post a reply to my self, but I can't help it. I thought of another way to do it, using the on exit event .

CODE

Private Sub CtlB_Exit(Cancel As Integer)
  Dim intResult As Integer

  If CtlB.Value = 0 Then
  intResult = MsgBox("CtlB must be filled in", vbOKCancel)
  Cancel = True
  End If
End Sub





User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 07:27PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month