index > Visual Basic for Applications (VBA) > List Box Search

List Box Search


I am developing in Access 2003. I have a form that has a record set associated to it. It allows you to edit one record at a time through text boxes for each field. To this form I added a list box (lstInstruments) from a query of the same table that the form is linked to.

In the AfterUpdate event of the list box I entered the following code.

Set rs = Me.Recordset.Clone
rs.FindFirst "[InstrumentID] = " & Str(Me![lstInstruments])
Me.Bookmark = rs.Bookmark

This allows me to have a list of all of the records on the form, select one in the list box and then the detail part of the form updates to the correct record.

Now I need to do the reverse. When I click on the record navigator buttons and move from record to record, I need to have the the ListIndex of the list box updated so that the proper record is highlighted in the list box. Is there a way to search the items in the list box to find the item where the the first column = [InstrumentsID] or do I have to go create a recordset of the same query that sources the list box a walk through those records one at a time with a counter to "calculate" the index number.

Roger Harden

Hello Roger,

I think I get what you mean. Does the order of the records matter, because if you use the same ordering for the items in the listbox and the records browsed with the form then you could use that to simplify the synchronisation between the record displayed in the form and the currently selected item in the list box.

You could also handle the events raised by the navigator button and, for example for the next record, just increment the selected index of the list box. That would be a very easy approach.

I hope that was helpful and was what you where looking for.




www.dsmyth.net/blog
Derek Smyth

I figured it out. Put this is the Current event of the main form.

Me.lstInstruments.Value = Me.InstrumentID

Roger Harden
:D easy as that! :D


www.dsmyth.net/blog
Derek Smyth
reply 4

You can use google to search for other answers

 

More Articles

• FTP in Excel Macro
• Problems with DAO and SQL Server
• Charts in Excel
• Accessing Tables in Access 2000 that are linked from an SQL Serve...
• About Error:"Unable to Set Visible Property PivotItem class&...
• Word Macro and Template File
• Edit Data in Access
• [Access 2000] Error when importing text files of certain extensio...
• Office XP VBA can't find reference after saving by Office 2003
• VBA Excel/Oracle query and run-time error 3146
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• VBA for Excel Query. From Someone New
• Bound form
• Global Variable not Persisting
• transmitting a string from excel to com1
• Code for end of month activity submissio
• Put Certain E-mail Address in FROM Field
• Question reg BeforeDoubleClick event in
• Can this be done via an array formula?
• ComboBox itemData as Long => error
• Macros - Excel
• Personal.xls
• VB writing data to an Excel file
• How to install MS Jet 4.0 OLE DB?
• VB in word 2000 / form built into a temp
• Problem with CWnd::RunModalLoop(DWORD dw

Hot Articles

• VBA install failed 536870930
• Detect visio shape double click
• 1004 - Application-Defined or Object-Def
• ACCESS 2003 OLE
• Referencing unregistered DLL
• Linking Infopath Toolbar Buttons to VBSc
• Another SendKeys
• Is VBA SDK free and ...?
• read-only OLEs ?
• Passing new parameters to rdlc reports
• VB to MSWORD BookMark
• Mail subject
• Data from serial port
• Stupid Question, how to turn Question Ma
• VBA script not accessing another workbook

Recommend Articles

• Defining a range according to the number
• VBA source code
• Loosing Reference to Common Objects (i.s
• Wildcards In Access
• Macros - Excel
• How to check the TCP/IP checkbox in netw
• Combo Box add items from excel column an
• File Protection from Users
• Create ProjectItem Error. (Core API)
• Accessing a subform, error 2455
• For Next stops at 16
• Fastest Processor for Running Excel VBA
• [OTP] VBA Using combobox in Excel
• Table or Array in the header of an excel
• How to read directory information into a