Problem with list box selecting individual records

%3CLINGO-SUB%20id%3D%22lingo-sub-2429911%22%20slang%3D%22en-US%22%3EProblem%20with%20list%20box%20selecting%20individual%20records%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2429911%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20I'm%20currently%20building%20a%20database%20with%20a%20'master'%20form%20that%20I%20want%20everyone%20to%20use%20instead%20of%20meddling%20around%20in%20the%20tables%20and%20such.%20I've%20got%20a%20couple%20of%20sub-forms%20opening%20up%20from%20here%2C%20including%20new%20record%20and%20edit%20record.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20lies%20with%20edit%20record%2C%20as%20I%20have%20made%20a%20list%20box%20to%20display%20the%20results%20from%20a%20search%20box.%20The%20results%20show%20up%20fine%2C%20and%20all%20records%20from%20each%20client%20are%20visible.%20However%2C%20when%20I%20go%20to%20select%20a%20specific%20record%2C%20it%20defaults%20to%20only%20one%20record%20per%20client.%20As%20most%20clients%20have%20multiple%20instances%20of%20software%2Fhardware%2C%20it%20doesn't%20allow%20me%20to%20open%20any%20of%20the%20alternative%20records%2C%20only%20one%20record%20per%20client.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20using%20a%20button%20to%20open%20the%20edit%20data%20sub%20form%2C%20and%20the%20code%20I%20have%20for%20the%20on%20click%20event%20is%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoCmd.OpenForm%20%22EditData%22%2C%20%2C%20%2C%20%22%5BClient_Database.Client%5D%3D%22%20%26amp%3B%20%22%20'%20%22%20%26amp%3B%20Me.EditRecordResults.Column(0)%20%26amp%3B%20%22%20'%20%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20EditRecordResults%20is%20the%20list%20box%2C%20and%20the%20after%20update%20code%20I%20have%20for%20the%20list%20box%20is%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEditRecordButton.Enabled%20%3D%20True%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEditRecordButton%20is%20the%20same%20button%20I%20have%20the%20on%20click%20event%20for.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20what%20could%20be%20causing%20this%3F%20I'm%20not%20sure%20if%20the%20event%20code%20causing%20the%20issue%2C%20or%20if%20access's%20default%20list%20box%20settings%20are%20limiting%20my%20options%2C%20although%20I%20don't%20know%20how%20to%20change%20these%20either.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20help%20would%20be%20greatly%20appreciated!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2429911%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAccess%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EList%20Box%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2431340%22%20slang%3D%22en-US%22%3ERe%3A%20Problem%20with%20list%20box%20selecting%20individual%20records%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2431340%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1074501%22%20target%3D%22_blank%22%3E%40DinkyDon%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20offer%20an%20in-depth%20answer%2C%20we'd%20need%20more%20detail%2C%20but%20in%20general%20it's%20possible%20to%20suggest%20some%20things%20for%20you%20to%20review.%3C%2FP%3E%3CP%3EFirst%2C%20the%20List%20box%20is%20bound%20to%20a%20particular%20column%2C%20which%20by%20default%20Column(0).%20As%20an%20aside%2C%20columns%20in%20list%20boxes%20as%20well%20as%20combo%20boxes%20are%20indexed%20from%20left%20to%20right%2C%20starting%20with%200.%20That%20means%20the%20first%20column%20on%20the%20left%20is%20Column(0).%20That's%20the%20one%20you%20are%20using%20according%20to%20your%20posted%20code.%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20column%20and%20selected%20row%20in%20the%20list%20box%20refers%20to%20one%20and%20only%20one%20value.%20That's%20the%20one%20which%20you%20indicate%20is%20being%20used%20to%20filter%20the%20second%20form%2C%20i.e.%20%22EditData%22.%20And%20that%20is%20why%20it%20only%20displays%20a%20single%20record.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20order%20to%20select%20MULTIPLE%20records%2C%20you%20have%20to%20figure%20out%20which%20values%20are%20common%20to%20all%20of%20the%20desired%20records%2C%20and%20that%20would%20be%20the%20one%20which%20relates%20to%20records%20in%20the%20other%20table%20containing%20those%20multiple%20records.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EThis%20is%20just%20a%20guess%2C%20based%20on%2025%2B%20years%20of%20experience%20and%20the%20hints%20available%20in%20your%20description.%20I%20imagine%20you%20have%20two%20tables%2C%20not%20one.%20And%20these%20tables%20would%20be%3C%2FP%3E%3CUL%3E%3CLI%3E%22Client%22%20in%20which%20the%20basic%20Client%20data%20is%20stored.%20Each%20client%20has%20one%20unique%20ID%20field%2C%20probably%20an%20AutoNumber.%26nbsp%3B%3C%2FLI%3E%3CLI%3E%22Equipment%22%20in%20which%20all%20of%20the%20equipment%20assigned%20or%20issued%20or%20sold%20to%20clients%20is%20recorded.%20Each%20Equipment%20record%20also%20has%20one%20unique%20ID%20field%2C%20probably%20also%20an%20AutoNumber.%20HOWEVER%2C%20and%20this%20is%20the%20important%20point%2C%20this%20Equipment%20table%20(or%20whatever%20you%20called%20your%20version%20of%20it)%20also%20has%20a%20field%20for%20the%20ClientID%20that%20relates%20back%20to%20the%20Client%20table.%20This%20allows%20you%20to%20record%20one%20or%20more%20pieces%20of%20equipment%20(software%20or%20hardware)%20for%20each%20client.%20And%20THAT%20is%20the%20table%20you%20want%20to%20refer%20to%20when%20opening%20this%20%22Edit%20Data%22%20form%20and%20that%20is%20the%20ClientID%20you%20want%20to%20pass%20to%20it%20in%20your%20VBA.%3C%2FLI%3E%3C%2FUL%3E%3CP%3EIt%20sounds%20like%20one%20of%20two%20possibilities%20is%20where%20the%20problem%20lies.%3C%2FP%3E%3CP%3EEither%20the%20%22Edit%20Data%22%20form%20is%20bound%20to%20the%20Client%20table%2C%20so%20you%20only%20get%20that%20one%20client%20record.%20You%20can%20not%20show%20multiple%20equipment%20records%20from%20the%20second%2C%20Equipment%2C%20table%20that%20way.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnother%20possibility%20is%20that%20the%20list%20box%20is%20bound%20to%20the%20Equipment%20table%20since%20what%20you%20want%20to%20do%20is%20work%20with%20multiple%20equipment%20records.%20And%20that%20means%20you%20should%20pass%20the%20ClientID%20to%20it%2C%20not%20the%20EquipmentID.%20If%20this%20is%20the%20scenario%20that%20applies%20to%20your%20situation%2C%20that%20means%2C%20I%20think%2C%20your%20list%20box%20Column(0)%20actually%20is%20bound%20to%20the%20EquipmentID%2C%20not%20to%20the%20ClientID%20and%20that%20is%20the%20value%20being%20sent%20to%20the%20Edit%20Data%20form.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3ESince%20I%20can't%20see%20how%20this%20is%20all%20set%20up%20in%20your%20form%2C%20as%20I%20say%2C%20this%20is%20just%20a%20series%20of%20educated%20guesses.%20Hopefully%2C%20though%2C%20it%20can%20send%20you%20in%20the%20right%20direction%20to%20look%20for%20answers.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hi, I'm currently building a database with a 'master' form that I want everyone to use instead of meddling around in the tables and such. I've got a couple of sub-forms opening up from here, including new record and edit record. 

 

The problem lies with edit record, as I have made a list box to display the results from a search box. The results show up fine, and all records from each client are visible. However, when I go to select a specific record, it defaults to only one record per client. As most clients have multiple instances of software/hardware, it doesn't allow me to open any of the alternative records, only one record per client. 

 

I'm using a button to open the edit data sub form, and the code I have for the on click event is:

 

DoCmd.OpenForm "EditData", , , "[Client_Database.Client]=" & " ' " & Me.EditRecordResults.Column(0) & " ' "

 

The EditRecordResults is the list box, and the after update code I have for the list box is:

 

EditRecordButton.Enabled = True

 

EditRecordButton is the same button I have the on click event for.

 

Any ideas what could be causing this? I'm not sure if the event code causing the issue, or if access's default list box settings are limiting my options, although I don't know how to change these either. 

 

Any help would be greatly appreciated!

1 Reply

@DinkyDon 

To offer an in-depth answer, we'd need more detail, but in general it's possible to suggest some things for you to review.

First, the List box is bound to a particular column, which by default Column(0). As an aside, columns in list boxes as well as combo boxes are indexed from left to right, starting with 0. That means the first column on the left is Column(0). That's the one you are using according to your posted code. 

That column and selected row in the list box refers to one and only one value. That's the one which you indicate is being used to filter the second form, i.e. "EditData". And that is why it only displays a single record. 

 

In order to select MULTIPLE records, you have to figure out which values are common to all of the desired records, and that would be the one which relates to records in the other table containing those multiple records. 

This is just a guess, based on 25+ years of experience and the hints available in your description. I imagine you have two tables, not one. And these tables would be

  • "Client" in which the basic Client data is stored. Each client has one unique ID field, probably an AutoNumber. 
  • "Equipment" in which all of the equipment assigned or issued or sold to clients is recorded. Each Equipment record also has one unique ID field, probably also an AutoNumber. HOWEVER, and this is the important point, this Equipment table (or whatever you called your version of it) also has a field for the ClientID that relates back to the Client table. This allows you to record one or more pieces of equipment (software or hardware) for each client. And THAT is the table you want to refer to when opening this "Edit Data" form and that is the ClientID you want to pass to it in your VBA.

It sounds like one of two possibilities is where the problem lies.

Either the "Edit Data" form is bound to the Client table, so you only get that one client record. You can not show multiple equipment records from the second, Equipment, table that way.

 

Another possibility is that the list box is bound to the Equipment table since what you want to do is work with multiple equipment records. And that means you should pass the ClientID to it, not the EquipmentID. If this is the scenario that applies to your situation, that means, I think, your list box Column(0) actually is bound to the EquipmentID, not to the ClientID and that is the value being sent to the Edit Data form. 

Since I can't see how this is all set up in your form, as I say, this is just a series of educated guesses. Hopefully, though, it can send you in the right direction to look for answers.