By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,101 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,101 IT Pros & Developers. It's quick & easy.

In Access, how to use SetFocus within the LostFocus procedure (for same control)

P: 4
hi

in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field)
i am using this code but not setfocuse to same field (this is my problem please give proper gidence for this problem) :-

Description about this code:-

Sex field is one combo box in two options male-1;female-2
IND_APPL is one combo box here options are applicable-1;not applicable-0

Expand|Select|Wrap|Line Numbers
  1. Private Sub IND_APPL_LostFocus()
  2. If Sex.Value = 1 And IND_APPL.Value = 0 Then
  3. Form_PHMRC.SIB1.SetFocus
  4. IND_Line.SetFocus
  5. Else
  6. If Sex.Value = 2 And IND_APPL.Value = 1 Then
  7. IND_N20.SetFocus
  8. Else
  9. MsgBox ("CHECK WITH SEX")
  10. IND_APPL.SetFocus
  11. End If
  12. End If
  13. End Sub
here every thing ok but this statement IND_APPL.setfocuse not respond properley
while giving this options Sex.value = 1 and IND_APPL.value = 1 and
Sex.value = 2 and IND_APPL.value = 0 (ELSE block)
it show msgbox CHECK WITH SEX properely
but it is not setfocus to IND_APPL this field (it is setfocuse to next field)

please give to me proper gidence how i will over come this problem
Mar 29 '07 #1
Share this Question
Share on Google+
3 Replies


pureenhanoi
100+
P: 175
hi

in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field)
i am using this code but not setfocuse to same field (this is my problem please give proper gidence for this problem) :-

Description about this code:-

Sex field is one combo box in two options male-1;female-2
IND_APPL is one combo box here options are applicable-1;not applicable-0

CODE:-

Private Sub IND_APPL_LostFocus()
If Sex.Value = 1 And IND_APPL.Value = 0 Then
Form_PHMRC.SIB1.SetFocus
IND_Line.SetFocus
Else
If Sex.Value = 2 And IND_APPL.Value = 1 Then
IND_N20.SetFocus
Else
MsgBox ("CHECK WITH SEX")
IND_APPL.SetFocus
End If
End If
End Sub

here every thing ok but this statement IND_APPL.setfocuse not respond properley
while giving this options Sex.value = 1 and IND_APPL.value = 1 and
Sex.value = 2 and IND_APPL.value = 0 (ELSE block)
it show msgbox CHECK WITH SEX properely
but it is not setfocus to IND_APPL this field (it is setfocuse to next field)

please give to me proper gidence how i will over come this problem
Try this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub IND_APPL_Validate(Cancel as Boolean)
  2. If condition=TRUE Then
  3.       Cancel = False
  4.       onotherTextBox.SetFocus
  5. Else
  6.       Cancel = TRUE
  7. End If
  8. End Sub
  9.  
You should set Cancel variable to TRUE to hold the focus at the same Text Field and to FALSE to allow focus to onother control.
Mar 29 '07 #2

Expert 5K+
P: 8,434
...You should set Cancel variable to TRUE to hold the focus at the same Text Field and to FALSE to allow focus to onother control.
Good idea. However, you don't need to explicitly set it to False - that is the default value.
Mar 29 '07 #3

vijaydiwakar
100+
P: 579
its not a good practise to use lostfocus
Try Validate Event
Mar 29 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.