LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default how to create dynamic web query through vb scrip?

Run the macro recorder on one query and explain which parameter you need to
change. The Command text portion of the query is the SQL statements which
are the parameters you are fetching from your data base. The SQL is a string
and you can make substitions like my example below

I have the original recorded macro and the new macro with the part number as
a varialble. I also modified the orginal recordeed macro so each parameter
is on its own line. the macro recorder makes loooooooong strings and it is
simple to break these string into multiple parts.

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2/26/2009
'

'
With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DSN=MS Access Database;" & _
"DBQ=C:\TEMP\Part Log.mdb;DefaultDir=C:\TEMP;" & _
"DriverId=25;" & _
"FIL=MS Access;" & _
"MaxBufferSize=2048;" & _
"PageTimeout"), _
Array("=5;")), _
Destination:=Range("A1"))

.CommandText = Array( _
"SELECT `0123 parts received`.ID," & _
"`0123 parts received`.Program," & _
"`0123 parts received`.`Part Number`," & _
Chr(13) & "" & Chr(10) & _
"FROM `C:\TEMP\Part Log`.", _
"`0123 parts received` `0123 parts received`")

.Name = "Query from MS Access Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Application.DefaultSheetDirection = xlLTR
ActiveSheet.DisplayRightToLeft = False
End Sub


Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2/26/2009
'
GetPartNumber = "9876"
'
With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DSN=MS Access Database;" & _
"DBQ=C:\TEMP\Part Log.mdb;DefaultDir=C:\TEMP;" & _
"DriverId=25;" & _
"FIL=MS Access;" & _
"MaxBufferSize=2048;" & _
"PageTimeout"), _
Array("=5;")), _
Destination:=Range("A1"))

.CommandText = Array( _
"SELECT `" & GetPartNumber & " parts received`.ID," & _
"`" & GetPartNumber & " parts received`.Program," & _
"`" & GetPartNumber & " parts received`.`Part Number`," & _
Chr(13) & "" & Chr(10) & _
"FROM `C:\TEMP\Part Log`.", _
"`" & GetPartNumber & " parts received` `" & GetPartNumber & "parts
received`")

.Name = "Query from MS Access Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Application.DefaultSheetDirection = xlLTR
ActiveSheet.DisplayRightToLeft = False
End Sub



"Comm

"Hemant Oswal" wrote:

i want to execute such a web query for which i am setting parameters in that
query.
I want to change parameters through visual basic script progrram and refresh
data.
how to do that programming.

 
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
To creat scrip ledger Rasik Excel Discussion (Misc queries) 1 June 27th 09 11:28 PM
in excel , arrange scrip names alphabatically logu Excel Discussion (Misc queries) 3 October 12th 08 05:06 PM
VB and Excel Scrip [email protected] Excel Programming 0 February 7th 07 03:00 PM
Dynamic Web Query from VBA ThisShouldBeEasy Excel Programming 3 May 24th 05 10:05 PM
Dynamic Web Query Amanda MMW Excel Programming 3 June 14th 04 07:24 PM


All times are GMT +1. The time now is 09:22 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"