Return to First Item in List Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello.

I have implemented an incremental search solution from the Access 2000
Developer's Handbook into one of my forms. The solution uses a text box on
top of a list box in order to simulate a permenantly open combo box which
searches as you type.

I have a button that clears the search values between searches similar to
the following:

Private Sub cmdClearSearch_Click()
Me.FilterOn = False
Me.txtIncSrch.Value = Null
Me.lstIncSrch.Value = Null
End Sub

The above procedure will clear the text from the text box and the
highlighted line from the list box, however, the list box will remain
scrolled down to where the last selected line was located. Is there a
statement I could add that would make the list box scroll back to the top
when I run the ClearSearch command?

Many Thanks!
 
I tried setting up the procedure to include the line you recommended like this:

Private Sub cmdClearSearch_Click()
Me.FilterOn = False
Me.txtIncSrch.Value = Null
Me.lstIncSrch.Selected(0) = True
Me.lstIncSrch.Value = Null
End Sub

It will clear the boxes and scroll the list box back to the top, however, I
get an error: "Update or CancelUpdate without AddNew or Edit." The error
will pop up over and over again whenever I try to click on different controls
or move between records, so I have to close the form in order to clear it.
When I close the form I get another error stating that changes to the current
record could not be saved.

Is there any way to move to the beginning of a list box without selecting a
value?
 
The selection shouldn't make any different because you cleared it with

Me.lstIncSrch.Value = Null

Do you have other code in the form, like OnCurrent or Before/After upate
that might cause the error?
 
Yes. There is a class module that uses "WithEvents" declarations for the
"OnChange" and "LostFocus" events of the text box as well as the
"AfterUpdate" event of the list box. Each letter typed into the text box
evokes the "OnChange" event to execute a search for a matching string in the
list box below. The "LostFocus" event causes the currently selected value of
the list box to be copied to the text box. The list box uses the
"AfterUpdate" event to copy any selected (clicked on) item into the text box
as well.

The two controls are set up so users can begin typing the title for a given
project in the text box and the list box below will scroll down to the most
closely matching entries. If the user leaves the text box control after
typing one or more characters, the currently highlighted list box value will
be copied into the text box. Alternatively, if the user clicks an item in
the list box it will be copied to the text box. From there, the user can
click a command button to filter the form based upon the value in the text
box.

Seeing as this rather complex search feature works flawlessly with the
exception of the one small aesthetic issue that I'm trying to correct -
please feel free to tell me if I should just leave well enough alone here.

Thank you again for your help.
 
Back
Top