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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handle of browsing through form controls with a LimitToList=Yes combo

Status
Not open for further replies.

Bresart

Programmer
Feb 14, 2007
314
ES
Hi, i have a form with several controls, which their KeyDown and KeyPress events are:



Private Sub AprovechCombo_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
If IsNull(Me.AprovechCombo.Text) = False And Trim(Me.AprovechCombo.Text) <> "" And enterNotInList = False Then
frutoCombo.visible = True
DoCmd.GoToControl "frutoCombo"
AprovechCombo.visible = False
Else
KeyCode = 0
End If
End If


Private Sub AprovechCombo_KeyPress(KeyAscii As Integer)
If enterNotInList = False Then
If KeyAscii = 13 Or KeyAscii = 9 Then
If IsNull(Me.AprovechCombo.Text) = False And Trim(Me.AprovechCombo.Text) <> "" And enterNotInList = False Then
frutoCombo.visible = True
DoCmd.GoToControl "frutoCombo"
AprovechCombo.visible = False
Else
KeyAscii = 0
End If
End If




The control AprovechCombo is a combobox with its property Limit to list set to Yes. Its NotInList event is:




Private Sub AprovechCombo_NotInList(NewData As String, Response As Integer)
MsgBox "El campo 'Aprovechamiento' debe ser un elemento de la lista. La lista de aprovechamientos puede editarse desde el formulario Ayuda.", 64, ""
Me.AprovechCombo.Dropdown
Response = acDataErrContinue
enterNotInList = True
End Sub



I use the enterNotInList boolean for avoiding that if the introduced text isn't in list the focus goes to the next control. But when the introduced text isn't in list and the tab key is pressed, the code gives the error 2110 : the application can't move the focus to the control frutoCombo. Though the enterNotInList value is True when the KeyDown event enters (it enters after NotInList event), the code runs what is into the if statement

If IsNull(Me.AprovechCombo.Text) = False And Trim(Me.AprovechCombo.Text) <> "" And enterNotInList = False Then


Any solution for going around that?

Thanks for looking.


 
Why explicitly set the active control? Why not make the tab order appropriate and if it is hidden, it will skip it? Have you tried the SetFocus method?

Me!frutoCombo.Setfocus

I doubt the setfocus would help but it is worth a try.
I think you have a timing issue in that the form is trying to resolve the key that changes the control and change the control.

Beyond that I'm not entirely comfortable with your methodology. I have only had to use a key event once and I would recommend avoiding it if possible. Usually a combination of afterupdate and and OnCurrent events can be used to test data.

 
Thanks lameid. I have solved it changing the lines order in the NotInList event:

Private Sub AprovechCombo_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue
enterNotInList = True
Me.AprovechCombo.Dropdown
MsgBox "El campo 'Aprovechamiento' debe ser un elemento de la lista. La lista de aprovechamientos puede editarse desde el formulario Ayuda.", 64, ""
End Sub
 
The solution has been mainly setting the Limit to list property to No, and checking in the event KeyPress and KeyDown if

Me.AprovechCombo.ListIndex = -1

and if not desplacing the focus to the next control.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top