+ Reply to Thread
Results 1 to 9 of 9

load a listbox in a form from data in a spreadsheet using a filtered Excel SQL statement

  1. #1
    Registered User
    Join Date
    01-06-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    10
    Posts
    39

    load a listbox in a form from data in a spreadsheet using a filtered Excel SQL statement

    In my Excel file there is a form and a spreadsheet. The form has a combo box and a listbox: cboFacility is populated by a list of faciltities; and lstConnections is populated by records in the spreadsheet. There are a number of columns in the spreadsheet (col1, col2, col3...coln, colFacility). Records are constantly being added to the spreadsheet via another process.

    I want to populate lstConnections with a SQL statement that takes filtered records from the spreadsheet. So when the user selects a facility from the cboFacility, an SQL statement is built like so: "SELECT col1, col2, col3,...coln FROM SPREADSHEET WHERE colFacility = cboFacility.value". Then lstConnections is populated by the filtered records.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: load a listbox in a form from data in a spreadsheet using a filtered Excel SQL stateme

    if your code already got recor(s) then something like
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    02-25-2022
    Location
    Dallas, Texas
    MS-Off Ver
    Office 365
    Posts
    174

    Re: load a listbox in a form from data in a spreadsheet using a filtered Excel SQL stateme

    You can do this by connecting to the worksheet as a database. The query can be very complex. Here is a tutorial. It is very fast.

    I do this to create reports. However, I don't recommend using Excel as a serious database with critical information. It is very easy to corrupt the workbook. I would recommend using Access or SQL Server Express (free).

  4. #4
    Registered User
    Join Date
    01-06-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    10
    Posts
    39

    Re: load a listbox in a form from data in a spreadsheet using a filtered Excel SQL stateme

    I agree, but constraints at the office prevent me from using Access or SQL Server. I have to use Excel.

  5. #5
    Registered User
    Join Date
    01-06-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    10
    Posts
    39

    Re: load a listbox in a form from data in a spreadsheet using a filtered Excel SQL stateme

    Thanks. Doesn't answer my question.

  6. #6
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: load a listbox in a form from data in a spreadsheet using a filtered Excel SQL stateme

    see big yellow banner - how to upload your workbook.
    far easier to then give you a task specific solution.
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  7. #7
    Registered User
    Join Date
    01-06-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    10
    Posts
    39

    Re: load a listbox in a form from data in a spreadsheet using a filtered Excel SQL stateme

    I've attached a sample file with the issue i described. When you select a facility from the combo box, a sql query is built using the selected facility as a filter. Then the query is executed, the results sent to a record set. I'm wondering how to populate the listbox with the recordset.
    Attached Files Attached Files

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: load a listbox in a form from data in a spreadsheet using a filtered Excel SQL stateme

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-06-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    10
    Posts
    39

    Re: load a listbox in a form from data in a spreadsheet using a filtered Excel SQL stateme

    Works perfectly. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Load data from excel table to word userform listbox
    By Undo in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2022, 05:03 PM
  2. Load Data Form Table to Order Form Using VLookUp in VBA
    By Ivy_1011 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-03-2022, 03:00 AM
  3. Load an listbox on a form with selected records off a spreadsheet in the same excel file
    By vancouver_ron in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-05-2020, 01:46 PM
  4. Filtered data in Listbox based on Option buttons EXCEL VBA
    By saucy_spider in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-20-2018, 12:36 AM
  5. Load Userform ComboBox with filtered data
    By anandvh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-20-2012, 05:34 PM
  6. Populate Listbox on Form Load
    By Kesey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2007, 10:52 PM
  7. Load data into a listbox
    By Jennifer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2005, 08:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1