PC Review


Reply
Thread Tools Rate Thread

how to create dynamic web query through vb scrip?

 
 
Hemant Oswal
Guest
Posts: n/a
 
      26th Feb 2009
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.

 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      26th Feb 2009
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(Array( _
"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(Array( _
"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.
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      26th Feb 2009
Establish your query>record a refresh>introduce your parameters into the
macro. If you can't figure it out send your wb to my address with complete
details and before/after examples.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Hemant Oswal" <Hemant (E-Mail Removed)> wrote in message
news:95ECD300-CD98-4AE7-A435-(E-Mail Removed)...
>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.
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a form to create dynamic Query and chart axwack Microsoft Access Forms 1 15th Dec 2007 08:18 PM
Create a Dynamic Search query =?Utf-8?B?c3VzYW5tZ2FycmV0dA==?= Microsoft Access Queries 1 2nd Nov 2007 06:00 AM
How to Create a Dynamic Query Beto1967 via AccessMonster.com Microsoft Access Queries 2 3rd Oct 2007 02:19 PM
change PC's DNS settings to dynamic via logon scrip in Nvell environment alfyalf@hotmail.co.uk Microsoft Windows 2000 Registry 11 3rd Feb 2007 04:36 AM
How do I create a dynamic link to a table within a query? =?Utf-8?B?UnViYmxl?= Microsoft Access Queries 2 22nd Jul 2005 03:05 PM


Features
 

Advertising
 

Newsgroups
 


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