ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Retrieving data with SQL from ODBC source (https://www.excelbanter.com/excel-programming/294889-retrieving-data-sql-odbc-source.html)

Clint[_2_]

Retrieving data with SQL from ODBC source
 
Need help with retrieving data using SQL via an ODBC source. Need to use a cell value as a retrieval key. Can someone point me to a good reference for this?

Greg Koppel

Retrieving data with SQL from ODBC source
 
Hi Clint,

Here is some code that you can modify. I have used a variable called User as
the entry from an Input box, but you can change it to reference a cell value
too.

User = InputBox("Who are you?", "Enter your name", "Bede")
With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DSN=MS Access Database;DBQ=P:\BugDataBase\DI
CM.mdb;DefaultDir=P:\BugDataBase;DriverId=281;FIL= MS
Access;MaxBufferSize=2048;Pag" _
), Array("eTimeout=5;")), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT `Bugs`.bug_id, `Bugs`.priority, `Bugs`.description,
`Bugs`.date, `Bugs`.bug_assignee, `Bugs`.reported_by, `Bugs`.resolution" _
, _
", `Bugs`.fixed" & Chr(13) & "" & Chr(10) & "FROM `P:\BugDataBase\DI
CM`.`Bugs` `Bugs`" & Chr(13) & "" & Chr(10) & "WHERE (`Bugs`.reported_by
Like '%" & User & "%')" _
)
.Name = "Query from MS Access Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With

HTH, Greg

"Clint" wrote in message
...
Need help with retrieving data using SQL via an ODBC source. Need to use

a cell value as a retrieval key. Can someone point me to a good reference
for this?




All times are GMT +1. The time now is 08:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com