LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Pass a filename to a query

I am getting a filename from the user with this code, but can't seem to get
it passed to the .CommandText part of the query. Can you point me in the
right direction?


Sub Get_Leak_Data()
Dim filename

Sheets.Add
ActiveSheet.Name = "Database"
Range("A1").Select
fileToOpen = Application _
.GetOpenFilename("Database Files (*.dbf), *.dbf")
filename = 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 filename.TESTREAD, filename.TESTFREQ, filename.TESTDATE,
filename.REPFREQ, filename.REPDATE" & Chr(13) & "" & Chr(10) & "FROM
filename filename" & Chr(13) & "" & Chr(10) & "ORDER BY filename.TESTREAD
DESC" _
)
.Name = "Query from CLI Laf"
.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
pass parameter to access query Bill Manville Links and Linking in Excel 4 May 1st 23 03:45 AM
Pass date parameter into MS Query Richard Edwards Excel Discussion (Misc queries) 2 June 20th 08 11:43 AM
Is it possible to pass a parameter into IN operator in Query? DennisS Excel Discussion (Misc queries) 0 June 26th 07 09:27 AM
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
set filename to <filename-date on open bob engler Excel Worksheet Functions 2 July 13th 06 05:11 AM


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

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"