ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem in ODBC Query (https://www.excelbanter.com/excel-programming/295632-re-problem-odbc-query.html)

shilps

Problem in ODBC Query
 

Hi,
I have a code as given below:
With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y("ODBC;DSN=M
Access Database;DBQ=" + CStr(datab) + ";DefaultDir=" + CStr(direc) _
+ ";DriverId=25;"), Array("FIL=M
Access;MaxBufferSize=2048;PageTimeout=5;")), _
Destination:=Range("AR1"))
.Sql = Array("SELECT DISTINCT " + CStr(field) + _
"" & Chr(13) & "" & Chr(10) & "FROM `" + CStr(datab) + "`."
CStr(table_name) _
+ " " + CStr(table_name) + "")
.FieldNames = True
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SavePassword = True
.SaveData = False

Actually the result of this query is stored in column AR and table nam
is the option selected from the ComboBox. The problem is that for al
but few options in the ComboBox, this query runs fine. But for fe
options , it gives error on line

.Refresh BackgroundQuery:=False

The options in the ComboBox are the names of the field names. Th
problem occurs only when I try to pick the data from the a particula
table while it works fine with other tables. This table was added t
the database at a later point but this should not be a cause of thi
problem, or cud it be?


Any idea why?
TIH
Shilp


-
shilp
-----------------------------------------------------------------------
Posted via http://www.mcse.m
-----------------------------------------------------------------------
View this thread: http://www.mcse.ms/message587856.htm


AA2e72E[_2_]

Problem in ODBC Query
 
Try enclosing the table name with square brackets. These are unnecessary for names that do not have an embedded space but mandatory when they do.


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

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