Results 1 to 11 of 11
  1. #1
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160

    how to populate a list box

    Hi I have a list box with the following Row Source:


    SELECT tblCommonNames.CommonName FROM tblCommonNames WHERE (((tblCommonNames.SpeciesID)= Forms!MempSpeciesfrm!SpeciesID) And ((tblCommonNames.NameLang)="English")) ORDER BY tblCommonNames.CommonName;

    and Row Source Type = Table/Query

    I've created a relationship between tblCommonNames and the forms table source

    What do I need to do / check to populate the list box?

    Thanks for any help

    David

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    What is the issue? What happens - error message, wrong results, nothing?

    Exactly what do you mean by 'populate' - show items list or save selected item to a field?

    Looks like what you have should create the items list.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi, Sorry I find it difficult to present the whole picture within this text box - at 3am, but in the light of day I'll try and make it clearer.
    I have a form displaying the first 3 fields below from the Plant Species table:

    Click image for larger version. 

Name:	tblMempSpecies.JPG 
Views:	15 
Size:	71.0 KB 
ID:	30668

    I also have a CommonNames table:

    Click image for larger version. 

Name:	tblCommonNames.JPG 
Views:	15 
Size:	65.7 KB 
ID:	30669

    There can be several common names in the same language for a species.

    On my form I want a list box that displays all the common names in English for the current species, so far I have

    List Box
    Row Source: SELECT tblCommonNames.CommonName FROM tblCommonNames WHERE (((tblCommonNames.SpeciesID)= Forms!MempSpeciesfrm!SpeciesID) And ((tblCommonNames.NameLang)="English")) ORDER BY tblCommonNames.CommonName;

    Row Source Type: Table/Query

    In the below relationships the form is based on MempSpecies and items for the listbox in the form are taken from tblCommonNames

    Click image for larger version. 

Name:	relationship.JPG 
Views:	15 
Size:	66.9 KB 
ID:	30667



























    My problem is that the listbox is empty - even though there are English names for the current species - and I'm not receiving any Error message or notificatiion of any problem.

    Thanks for any help

    David

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    You mean there are no items listed? Are you navigating records? Do you have code that requeries the listbox when moving to another record?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Correct there are no items listed, yes I am navigating records, no I have no code.

    Here is the property sheet data tab for the list box:
    Click image for larger version. 

Name:	listbox.JPG 
Views:	13 
Size:	48.0 KB 
ID:	30672
    Last edited by mdavid; 10-07-2017 at 05:08 AM. Reason: added property sheet

  6. #6
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    You need to requery listbox when the form goes to another record if you haven’t already done so.

    On the form update event maybe as list9.requery

  7. #7
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    In post #3 you gave a query string as the rowsource, but in post #5 it shows a named query. Does running that named query show any rows? Does it throw an error?
    Seeing a pic of the property format tab would also be helpful.

  8. #8
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi,

    Made a little progress, I discovered that the column width was 0 so I increased it, now I see values in the listbox, but they don't change when I navigate thru the MempSpecies table, they're fixed on the value for the 1st record.
    Another question do I need a Control Source for the list box?

    The named query SQL view:
    SELECT tblCommonNames.CommonName
    FROM tblCommonNames
    WHERE (((tblCommonNames.SpeciesID)=[forms]![MempSpeciesfrm]![SpeciesID]) AND ((tblCommonNames.NameLang)="Hebrew"))
    ORDER BY tblCommonNames.CommonName;

    Running the query works if I replace [forms]![MempSpeciesfrm]![SpeciesID] with a specific value

    Below is the listbox property format tab

    Click image for larger version. 

Name:	listbox-frmt1.jpg 
Views:	12 
Size:	84.5 KB 
ID:	30673 Click image for larger version. 

Name:	listbox-frmt2.jpg 
Views:	12 
Size:	40.4 KB 
ID:	30674






































    Thanks for all your help
    David

  9. #9
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    Code:
    private sub Form_Current()
        list9.requery
    end sub

  10. #10
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Dave this looks good, excuse my ignorance how/where do I implement it?

    OK got it - form property sheet > on current > code builder

    How come this doesn't happen automatically when forms!MercSpecies! SpeciesID changes

    Thanks, your help is much appreciated, now I can get some sleep!

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    You would also need the same code in the SpeciesID AfterUpdate event or the SpeciesName GotFocus event.

    Also, set the SpeciesName field to Null in the SpeciesID AfterUpdate event. Because if the SpeciesID is changed, the saved SpeciesName is no longer appropriate.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Populate List Box & Read Value From VBA
    By Juan4412 in forum Programming
    Replies: 3
    Last Post: 05-29-2017, 01:19 PM
  2. How to populate list box from an array?
    By AAAndy in forum Forms
    Replies: 5
    Last Post: 08-19-2016, 08:23 AM
  3. Populate Combo Box with list of Tables
    By Varda in forum Forms
    Replies: 4
    Last Post: 06-07-2013, 08:07 AM
  4. Replies: 1
    Last Post: 11-23-2012, 10:26 PM
  5. List box to populate other list boxes
    By Nathan in forum Forms
    Replies: 0
    Last Post: 03-03-2009, 07:22 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums