Stay in the same field after events execution

  • Thread starter Thread starter Pantelis
  • Start date Start date
P

Pantelis

I use the following code to control the input of a
combobox [cboSelection] to find a specific record in a
form:
Private Sub cboSelect_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "
Code:
 = '" & Me![cboSelect] & "'"
If rs.NoMatch Then
MsgBox "No such Code", vbOKOnly
Else
Me.Bookmark = rs.Bookmark
End If
End Sub

The problem is that when NoMatch is TRUE and after the OK
button of the MsgBox is pressed the focus is lost from
[cboSelection] and the user has to move again to the
[cboSelection] to give a new value.
How I can keep the focus to [cboSelection]?

Tanks in advanced
Pantelis
 
Not a direct answer but if you use the a query with same criteria as the
RecordSource of the Form as the RowSouce for the ComboBox, i.e. there is a
one-to-one correspondence between the rows of the ComboBox and the Form's
Recordset, then the NoMatch never happens and you don't have to set the
Focus back to the ComboBox.

This helps the users as well since they can only select what the Form can
show.
 
Is needed to check for new values because so NoMatch is
always possible.
I tryied " Me![cboSelect].SetFocus " after the MsgBox but
it steel goes to next field maybe because its inside the
event and the focus isn't yet lost.

Any other ideas please

Pantelis.
-----Original Message-----
Not a direct answer but if you use the a query with same criteria as the
RecordSource of the Form as the RowSouce for the ComboBox, i.e. there is a
one-to-one correspondence between the rows of the ComboBox and the Form's
Recordset, then the NoMatch never happens and you don't have to set the
Focus back to the ComboBox.

This helps the users as well since they can only select what the Form can
show.

--
HTH
Van T. Dinh
MVP (Access)




Pantelis said:
I use the following code to control the input of a
combobox [cboSelection] to find a specific record in a
form:
Private Sub cboSelect_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "
Code:
 = '" & Me![cboSelect] & "'"
If rs.NoMatch Then
MsgBox "No such Code", vbOKOnly
Else
Me.Bookmark = rs.Bookmark
End If
End Sub

The problem is that when NoMatch is TRUE and after the OK
button of the MsgBox is pressed the focus is lost from
[cboSelection] and the user has to move again to the
[cboSelection] to give a new value.
How I can keep the focus to [cboSelection]?

Tanks in advanced
Pantelis[/QUOTE]


.
[/QUOTE]
 
Don't think you read my post properly: If the RowSource is the same (but
smaller number of columns, perhaps) as the RecordSource of the Form, then
you ALWAYS have a one-to-one correspondence, i.e. for ANY row the user
select in the ComboBox, there is ALWAYS a Row/Record in the Form's Recordset
that will match you posted FindFirst Method and therefore the NoMatch case
is redundant.
 
Sorry if I'm comming back again but I have to take in mind
that the records are to many so the user offen types the
Code:
 directly and it's possible to misstype so I need a
solution with the NoMatch included.

Thanks again for your patience,
Pantelis
[QUOTE]
-----Original Message-----
Don't think you read my post properly:  If the RowSource is the same (but
smaller number of columns, perhaps) as the RecordSource of the Form, then
you ALWAYS have a one-to-one correspondence, i.e. for ANY row the user
select in the ComboBox, there is ALWAYS a Row/Record in the Form's Recordset
that will match you posted FindFirst Method and therefore the NoMatch case
is redundant.

--
HTH
Van T. Dinh
MVP (Access)



[QUOTE="Pantelis"]
Is needed to check for new values because so NoMatch is
always possible.
I tryied " Me![cboSelect].SetFocus " after the MsgBox but
it steel goes to next field maybe because its inside the
event and the focus isn't yet lost.

Any other ideas please

Pantelis.
[/QUOTE]



.
[/QUOTE]
 
Set the LimitToList Property of the ComboBox to Yes / True and also use the
NotInList Event to give the user a message that what he / she types in not
available.

You may like to set the AutoExpand Property to Yes / True also.

The whole idea of a ComboBox is to let the user select an item easily, not
typing the whole entry. Even when the user elects to type, the ComboBox
should "autoexpand" to help the use.

If you use the ComboBox Wizard to create the ComboBox to do this, you will
find that the Wizard set up the ComboBox exactly as I described.
 
Back
Top