Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Excel getting info from Access

I have recorded this macro that modifies the information that I am pulling
into Excel from an Access query. About half way down, there is a line that
says, "WHERE (invexcption.Area='US006')". I know that I can modify the code
to bring back another areas information. for example,
invexcption.Area='US007'.

I would like to be able to make the Area a variable, so that I can create
and save a different file for each area... but cannot seem to get it to work.

Does anyone have any thoughts?

With ActiveWorkbook.Connections("Query from MS Access
Database").ODBCConnection
.BackgroundQuery = True
.CommandText = Array( _
"SELECT invexcption.Area, invexcption.`Client No`,
invexcption.`Client Name`, invexcption.SEC, invexcption.`CP Name`" _
, _
", invexcption.`Net Unbilled`, invexcption.`Net Billed`,
invexcption.`net Invty`" & Chr(13) & "" & Chr(10) & "FROM
`C:\MonthlyReportingPackage\F" _
, "inRpting.mdb`.invexcption invexcption" & Chr(13) & "" & Chr(10) &
"WHERE (invexcption.Area='US006')")
.CommandType = xlCmdSql
.Connection = Array(Array( _
"ODBC;DSN=MS Access
Database;DBQ=C:\MonthlyReportingPackage\FinRpting. mdb;DefaultDir=C:\MonthlyReportingPackage;DriverId =25;FIL=MS Ac" _
), Array("cess;MaxBufferSize=2048;PageTimeout=5;"))
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Excel getting info from Access

Declare a string and populate it from a variable:

dim strSql as string
strSql = "Select blah, blah2, blah3 from mytable where blah4 = ' " &
MyVariable & " ' "

..commandtext = strSql

etc.

Sam



"ruffnro" wrote:

I have recorded this macro that modifies the information that I am pulling
into Excel from an Access query. About half way down, there is a line that
says, "WHERE (invexcption.Area='US006')". I know that I can modify the code
to bring back another areas information. for example,
invexcption.Area='US007'.

I would like to be able to make the Area a variable, so that I can create
and save a different file for each area... but cannot seem to get it to work.

Does anyone have any thoughts?

With ActiveWorkbook.Connections("Query from MS Access
Database").ODBCConnection
.BackgroundQuery = True
.CommandText = Array( _
"SELECT invexcption.Area, invexcption.`Client No`,
invexcption.`Client Name`, invexcption.SEC, invexcption.`CP Name`" _
, _
", invexcption.`Net Unbilled`, invexcption.`Net Billed`,
invexcption.`net Invty`" & Chr(13) & "" & Chr(10) & "FROM
`C:\MonthlyReportingPackage\F" _
, "inRpting.mdb`.invexcption invexcption" & Chr(13) & "" & Chr(10) &
"WHERE (invexcption.Area='US006')")
.CommandType = xlCmdSql
.Connection = Array(Array( _
"ODBC;DSN=MS Access
Database;DBQ=C:\MonthlyReportingPackage\FinRpting. mdb;DefaultDir=C:\MonthlyReportingPackage;DriverId =25;FIL=MS Ac" _
), Array("cess;MaxBufferSize=2048;PageTimeout=5;"))
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With

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
Pull info from access to excel userfom and edit an existing record sam Excel Programming 1 November 17th 09 09:58 PM
Access Outlook appointment info and export into an Excel spreadsheet cmonroe21 via OfficeKB.com Excel Programming 1 February 18th 09 09:12 PM
Pull info from access to template in excel????? jwr Excel Programming 6 August 27th 05 03:52 AM
info in Excel import into Access to combine multiple records then. farm dog dad Excel Programming 1 July 1st 05 12:38 AM
Importing access database info into excel jwr Links and Linking in Excel 2 April 11th 05 02:13 PM


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