LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default DB query syntax

I too don't think you need Chr(13) & Chr(10) and what's the point in
aliasing your table (with its own name) if it's the only table? As you
have proved, adding such superfluous constructs causes confusion.
Instead try this:

.CommandText = Array("SELECT TESTREAD,TESTFREQ," & _
"TESTDATE,REPFREQ,REPDATE FROM " & _
fname & " ORDER BY TESTREAD DESC")

--

"George Nicholson" wrote in message ...
"SELECT" should be "SELECT ". I'm not sure that a missing space would
classify as a List separator, so it may be something else.

"FROM " & fname & " " & fname & " & Chr(13) etc. appears to have an orphaned
" after the 2nd fname. That would through off the OpenQuote/CloseQuote
pairing that the compiler does and generate an error similar to what you are
getting.

I am unfamiliar with the Chr(13) & "" & Chr(10) construction used in a SQL
statement, but maybe I should get out more. I can't say that they are a
problem but I do wonder if they are gumming up the works. You might try
removing them, just make sure you leave a space preceding " FROM" and "
ORDERBY".
--
George Nicholson

Remove 'Junk' from return address.


"Mike Fogleman" wrote in message
...
Can anyone see the syntax problem in this query in the .CommandText line?

It
gives me a Compile Error: Expected: List separator or ). I just don't see
it. Maybe a fresh pair of eyes can spot it.
Many thanks, Mike.

Sub Get_Data()
Dim fname

Sheets.Add
ActiveSheet.Name = "Database"
Range("A1").Select
fileToOpen = Application _
.GetOpenFilename("Database Files (*.dbf), *.dbf")
fname = Mid(fileToOpen, 9, 7)

With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _


"ODBC;CollatingSequence=ASCII;DBQ=c:\LES5;DefaultD ir=c:\LES5;Deleted=0;Drive
r={Microsoft dBase Driver (*.dbf)};DriverId=533;FIL=dBase" _
), Array( _
"

5.0;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5 ;SafeTransactions=0;Statis
tics=0;Threads=3;UserCommitSync=Yes;" _
)), Destination:=Range("A1"))
.CommandText = Array("SELECT" & fname & ".TESTREAD," & fname &
".TESTFREQ," & fname & ".TESTDATE," & fname & ".REPFREQ," & fname &
".REPDATE" & Chr(13) & "" & Chr(10) & "FROM " & fname & " " & fname & " &
Chr(13) & "" & Chr(10) & "ORDER BY " & fname & ".TESTREAD DESC")
.Name = fname
.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
End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax error in VBA in query from Access Winget Excel Discussion (Misc queries) 0 January 21st 10 07:49 PM
MS Query Oracle syntax Jeff[_3_] Excel Discussion (Misc queries) 3 May 12th 07 03:06 AM
MS Query Oracle syntax Jeff[_3_] Excel Discussion (Misc queries) 0 May 11th 07 09:26 PM
Microsoft Query syntax Krish Excel Discussion (Misc queries) 0 October 7th 05 02:33 PM
MS Query - Alias syntax David P Excel Worksheet Functions 3 February 16th 05 09:29 AM


All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"