Results 1 to 6 of 6
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    LstBox Assistance...Not sure how to word it

    Hi all,
    I have a table, tblPerson and in that table i have the PersonID, FirstName, LastName, sFirstName, sLastName and some other stuff not related to my question at hand....

    I am trying to create a form with a listbox and then a search filter to filter that list.

    What I am wondering or asking is, is there anyway to pull the ID, First, sFirst, and Last name into the list box as two records? So I can search for a name wether it be the first name or sfirst name in the search filter.
    First would be first name, sFirst would be spouce first name and last for both.... If spouce name was not null....

    Id First Name Last Name
    1 David Pierce


    1 Jonna Pierce
    2 Robert Howard
    ad so on.

    Basicall take the two names from one record and make them two records?
    Any assistance would be just fantastic. Have been trying several qrys, list box and so forth but cannot seem to bring both names from a record and make two out of them
    Thanks
    Dave

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    a listbox does not have a filter property, you need to change the rowsource - perhaps something like this in the search field after update or a search button click event

    me.listbox.rowsource="SELECT * FROM myTable WHERE firstname like '*" & me.searchbox & "*' OR lastname like '*" & me.searchbox & "*'"

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    Create a union query and use that as the row source for the listbox:
    "SELECT PersonID, FirstName As First_Name, LastName As Last_Name FROM tblPerson
    UNION
    SELECT
    PersonID, sFirstName as First_Name, sLastName As Last Name FROM tblPerson;"

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thanks Gicu,
    That worked however,....get ready....LOL
    Is there a way to remove any null in the second SELECT?
    Meaning there will always be a FirstName and LastName.... but a lot of the time their wont be a sFirstname, sLastName so that shows up a blank record.
    thanks again

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Figured it out
    Thank you everyone

    Code:
    SELECT DISTINCT tblPerson.PersonID, tblPerson.Firstname AS FirstName, tblPerson.LastName AS LastName
    FROM tblPerson
    UNION SELECT DISTINCT tblPerson.PersonID, tblPerson.sFirstname AS FirstName, tblPerson.sLastName AS LastName
    FROM tblPerson WHERE sFirstName IS NOT NULL;

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 7
    Last Post: 06-07-2017, 11:20 AM
  2. Word Merge Assistance
    By NONEN in forum Import/Export Data
    Replies: 1
    Last Post: 03-21-2016, 01:15 PM
  3. Replies: 8
    Last Post: 04-14-2013, 01:33 PM
  4. Call word object and import word fields
    By silverspr in forum Programming
    Replies: 3
    Last Post: 12-10-2012, 11:32 PM
  5. Access to Word - Multiple Word Templates?
    By alpinegroove in forum Programming
    Replies: 11
    Last Post: 06-12-2012, 04:42 PM

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