text field value remain selected

R

RipperT

Hi, The following code allows the user to search for a record using a combo
box. If the record is not found, the message appears. When the user clicks
OK, I would like the fields contents to remain selected, ready to accept the
next entry. This code is not doing it in the after_update event. The combo
box field retains focus, but the text is not highlighted - just a cursor in
front of the text. I have also tried using SetFocus to set the focus to
different field, then set it back to the combo box, but that doesn't work
either. Can anyone help? Many thanx. (Access 2002)

Private Sub Combo206_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[InmateId] = '" & Me![Combo206] & "'"
If rs.NoMatch Then
MsgBox "The inmate number you entered is not in the database."
Else
Me.Bookmark = rs.Bookmark
End If
Forms!frmInmates!Combo206.SetFocus
With Combo206
.SelStart = 0
.SelLength = Len(Combo206)
End With

End Sub
 
D

Dirk Goldgar

RipperT @comcast.net> said:
Hi, The following code allows the user to search for a record using a
combo box. If the record is not found, the message appears. When the
user clicks OK, I would like the fields contents to remain selected,
ready to accept the next entry. This code is not doing it in the
after_update event. The combo box field retains focus, but the text
is not highlighted - just a cursor in front of the text. I have also
tried using SetFocus to set the focus to different field, then set it
back to the combo box, but that doesn't work either. Can anyone help?
Many thanx. (Access 2002)

Private Sub Combo206_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[InmateId] = '" & Me![Combo206] & "'"
If rs.NoMatch Then
MsgBox "The inmate number you entered is not in the database."
Else
Me.Bookmark = rs.Bookmark
End If
Forms!frmInmates!Combo206.SetFocus
With Combo206
.SelStart = 0
.SelLength = Len(Combo206)
End With

End Sub

Why not set the combo box's Limit to List property to Yes, and use the
NotInList event to intercept the attempted entry of an incorrect inmate
number. The will keep the focus in the combo box, and probably keep the
text highlighted as well.
 
G

Guest

I tried that and after clicking OK, the combo box drop down list drops down
and the field value is not selected. My intention if for this to be a quick
lookup for users to see if the inmate number exists in the DB. I really need
for the field to be highlighted.

Thanx,

Rip

Dirk Goldgar said:
RipperT @comcast.net> said:
Hi, The following code allows the user to search for a record using a
combo box. If the record is not found, the message appears. When the
user clicks OK, I would like the fields contents to remain selected,
ready to accept the next entry. This code is not doing it in the
after_update event. The combo box field retains focus, but the text
is not highlighted - just a cursor in front of the text. I have also
tried using SetFocus to set the focus to different field, then set it
back to the combo box, but that doesn't work either. Can anyone help?
Many thanx. (Access 2002)

Private Sub Combo206_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[InmateId] = '" & Me![Combo206] & "'"
If rs.NoMatch Then
MsgBox "The inmate number you entered is not in the database."
Else
Me.Bookmark = rs.Bookmark
End If
Forms!frmInmates!Combo206.SetFocus
With Combo206
.SelStart = 0
.SelLength = Len(Combo206)
End With

End Sub

Why not set the combo box's Limit to List property to Yes, and use the
NotInList event to intercept the attempted entry of an incorrect inmate
number. The will keep the focus in the combo box, and probably keep the
text highlighted as well.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

RipperT said:
I tried that and after clicking OK, the combo box drop down list
drops down and the field value is not selected. My intention if for
this to be a quick lookup for users to see if the inmate number
exists in the DB. I really need for the field to be highlighted.

Thanx,

Rip

Dirk Goldgar said:
RipperT @comcast.net> said:
Hi, The following code allows the user to search for a record using
a combo box. If the record is not found, the message appears. When
the user clicks OK, I would like the fields contents to remain
selected, ready to accept the next entry. This code is not doing it
in the after_update event. The combo box field retains focus, but
the text is not highlighted - just a cursor in front of the text. I
have also tried using SetFocus to set the focus to different field,
then set it back to the combo box, but that doesn't work either.
Can anyone help? Many thanx. (Access 2002)

Private Sub Combo206_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[InmateId] = '" & Me![Combo206] & "'"
If rs.NoMatch Then
MsgBox "The inmate number you entered is not in the
database." Else
Me.Bookmark = rs.Bookmark
End If
Forms!frmInmates!Combo206.SetFocus
With Combo206
.SelStart = 0
.SelLength = Len(Combo206)
End With

End Sub

Why not set the combo box's Limit to List property to Yes, and use
the NotInList event to intercept the attempted entry of an incorrect
inmate number. The will keep the focus in the combo box, and
probably keep the text highlighted as well.

Okay, try this. Use the combo's BeforeUpdate event to validate the
entry, and the AfterUpdate event -- which will not be allowed to fire
unless the entry is accepted -- to reposition the form. Code might be
like this:

'----- start of suggested code -----
Private Sub Combo206_AfterUpdate()

With Me.RecordsetClone
.FindFirst "[InmateId] = '" & Me![Combo206] & "'"
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With

End Sub

Private Sub Combo206_BeforeUpdate(Cancel As Integer)

With Me!Combo206
If .ListIndex = -1 Then
MsgBox _
"The inmate number you selected is not in the database."
Cancel = True
.SelStart = 0
.SelLength = Len(.Text)
End If
End With

End Sub
'----- end of suggested code -----

Of course, you'll have to requery the combo box whenever a record is
added to or deleted from the combo box's rowsource table, or if a
record's InmateID is modified.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top