Results 1 to 1 of 1

Pass query to ListBox to select record

Threaded View

  1. #1
    Registered User
    Join Date
    10-02-2013
    Location
    Norfolk
    MS-Off Ver
    Excel 2007
    Posts
    9

    Pass query to ListBox to select record

    I am trying to find out if there is a way to pass the results of a query back to a userform listbox that the user can then scroll through select the client and load this into a sheet. so far this is the code that I have:

    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
            "ODBC;DBQ=C:\MBL\CDB\mbcdb.mdb;DefaultDir=C:\MBL\CDB;Driver={Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS Access;MaxBufferS" _
            ), Array( _
            "ize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UserCommitSync=Yes;" _
            )), Destination:=Range("$A$1")).QueryTable
            .CommandText = Array( _
            "SELECT `Client Details`.`Title (Client)`, `Client Details`.`ForeName (Client)`, `Client Details`.`Surname (Client)`, `Client Details`.`DOB (Client)#`, `Employer Details (Client)`.`Gross Annual Income " _
            , _
            "(Employer-Client)`, `Employer Details (Client)`.`Net monthly earned income (Employer-Client)`, `Employer Details (Client)`.`Guaranteed Overtime (Employer-Client)`, `Employer Details (Client)`.`Regular" _
            , _
            " Overtime (Employer-Client)`" & Chr(13) & "" & Chr(10) & "FROM `C:\MBL\CDB\mbcdb`.`Client Details` `Client Details`, `C:\MBL\CDB\mbcdb`.`Employer Details (Client)` `Employer Details (Client)`" & Chr(13) & "" & Chr(10) & "WHERE `Client Details`.Client_ID = " _
            , _
            "`Employer Details (Client)`.Client_ID AND ((`Client Details`.`Surname (Client)`='" & TextBox1.Value & "') AND (`Client Details`.`DOB (Client)#`='" & Format(CDate(DTPicker1.Value), "dd/mm/yyyy") & "'))" _
            )
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .ListObject.DisplayName = "Table_Query_from_TheKey"
            .Refresh BackgroundQuery:=False
        End With
    At the moment this passes the result directly to the active sheet. This could be multiple records which is not what I want, I only want a specific record as selected from the listbox. I have also attached an image of my userform.

    Any help greatly appreciated.
    Attached Images Attached Images

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] if anything in listbox select first item, if listbox empty do nothing (listbox in userform
    By mcdermott2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2015, 12:49 PM
  2. Pass "select all" parameter to ODBC query
    By ColoradoJay in forum Excel General
    Replies: 0
    Last Post: 04-22-2012, 05:57 PM
  3. Delete record from one side of select query
    By Cheeky Charlie in forum Access Tables & Databases
    Replies: 1
    Last Post: 10-29-2010, 04:56 PM
  4. Multi-Select Forms ListBox in Sheet to Array to Query
    By Lambshanks in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2009, 04:10 PM
  5. Select multiple listbox items and pass to an array
    By golzilla in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-13-2005, 05:49 PM

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