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.
Bookmarks