Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Import external data from Access query with Variable

Hello - I have been able to record a macro where I can change the
"inventory.Area" from US006 to US007. I would like to be able to make the
area a variable and pick up the area code from within a spreadsheet.

For example, I am doing reporting for 10 areas and would like to have one
template that pulls in the data from Access for one area, saves the file,
goes to the next area, pulls in that data from Access and so on. But I
cannot figure out how to make the area in the VBcode below a variable.

Any help would be appreciated.

Sub Macro3()
With Selection.QueryTable
.Connection = Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=C:\Documents and
Settings\ruffnro\My Documents\__Reporting\Monthly Reporting\_ Financial
Reporting.m" _
), Array( _
"db;DefaultDir=C:\Documents and Settings\ruffnro\My
Documents\__Reporting\Monthly Reporting;DriverId=25;FIL=MS Access;MaxBufferS"
_
), Array("ize=2048;PageTimeout=5;"))
.CommandText = Array( _
"SELECT inventory.Area, inventory.`Client No`, inventory.`Client
Name`, inventory.SEC, inventory.`CP Name`, inventory.`Net Unbilled`,
inventory.`Net Billed`, inventory.`net Invty`" & Chr(13) & "" & Chr(10) &
"FROM inventory inven" _
, "tory" & Chr(13) & "" & Chr(10) & "WHERE (inventory.Area='US007')")
.Refresh BackgroundQuery:=False
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Import external data from Access query with Variable

Dim sTheArea As String
sTheArea = ActiveSheet.Range("A1").Value

"WHERE (inventory.Area='" & sTheArea & "')")

"ruffnro" wrote:

Hello - I have been able to record a macro where I can change the
"inventory.Area" from US006 to US007. I would like to be able to make the
area a variable and pick up the area code from within a spreadsheet.

For example, I am doing reporting for 10 areas and would like to have one
template that pulls in the data from Access for one area, saves the file,
goes to the next area, pulls in that data from Access and so on. But I
cannot figure out how to make the area in the VBcode below a variable.

Any help would be appreciated.

Sub Macro3()
With Selection.QueryTable
.Connection = Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=C:\Documents and
Settings\ruffnro\My Documents\__Reporting\Monthly Reporting\_ Financial
Reporting.m" _
), Array( _
"db;DefaultDir=C:\Documents and Settings\ruffnro\My
Documents\__Reporting\Monthly Reporting;DriverId=25;FIL=MS Access;MaxBufferS"
_
), Array("ize=2048;PageTimeout=5;"))
.CommandText = Array( _
"SELECT inventory.Area, inventory.`Client No`, inventory.`Client
Name`, inventory.SEC, inventory.`CP Name`, inventory.`Net Unbilled`,
inventory.`Net Billed`, inventory.`net Invty`" & Chr(13) & "" & Chr(10) &
"FROM inventory inven" _
, "tory" & Chr(13) & "" & Chr(10) & "WHERE (inventory.Area='US007')")
.Refresh BackgroundQuery:=False
End With
End Sub

Reply
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
Import external data - web query Vijay Kotian Excel Discussion (Misc queries) 3 May 15th 07 01:43 PM
Import Data -- External Web Query Ted Metro Excel Worksheet Functions 1 March 20th 07 11:24 PM
How to do Edit Query from Import External Data. Excel General Questions Excel Discussion (Misc queries) 1 July 10th 06 10:35 AM
Import External Data/New WEB Query Carl Hopkins Excel Discussion (Misc queries) 0 February 10th 06 02:56 AM
import external data, web query Tim[_43_] Excel Programming 1 April 9th 05 03:42 PM


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