Macro to import external data from Access query to Excel

I have tried to post this a couple times, but don't see it after I post it... 
so if it out here three times, I am sorry!

I am trying to write code that will allow me to pull in information for 
different areas depending on the file that I am creating.  For example, I 
will create a file for US006 and want the external information for US006 and 
then create a file for US007 and want the information for US007.

I created the code below.  The fourth line from the bottom references US006. 
 I would like that to be a variable dependent on the file I am creating.  I 
cannot seem to get it to work.

Is this doable?

Thanks for your help.

Sub Macro7()
    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='US006')")
        .Refresh BackgroundQuery:=False
    End With
End Sub

0
Utf
11/25/2009 4:03:01 PM
excel.programming 6508 articles. 2 followers. Follow

2 Replies
1217 Views

Similar Articles

[PageSpeed] 59

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

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


"ruffnro" wrote:

> I have tried to post this a couple times, but don't see it after I post it... 
> so if it out here three times, I am sorry!
> 
> I am trying to write code that will allow me to pull in information for 
> different areas depending on the file that I am creating.  For example, I 
> will create a file for US006 and want the external information for US006 and 
> then create a file for US007 and want the information for US007.
> 
> I created the code below.  The fourth line from the bottom references US006. 
>  I would like that to be a variable dependent on the file I am creating.  I 
> cannot seem to get it to work.
> 
> Is this doable?
> 
> Thanks for your help.
> 
> Sub Macro7()
>     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='US006')")
>         .Refresh BackgroundQuery:=False
>     End With
> End Sub
> 
0
Utf
11/25/2009 4:19:02 PM
"WHERE (inventory.Area='US006')")

to

"WHERE ((inventory.Area)='US006')"

or 

"WHERE [inventory.Area]='US006'"

"ruffnro" wrote:

> I have tried to post this a couple times, but don't see it after I post it... 
> so if it out here three times, I am sorry!
> 
> I am trying to write code that will allow me to pull in information for 
> different areas depending on the file that I am creating.  For example, I 
> will create a file for US006 and want the external information for US006 and 
> then create a file for US007 and want the information for US007.
> 
> I created the code below.  The fourth line from the bottom references US006. 
>  I would like that to be a variable dependent on the file I am creating.  I 
> cannot seem to get it to work.
> 
> Is this doable?
> 
> Thanks for your help.
> 
> Sub Macro7()
>     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='US006')")
>         .Refresh BackgroundQuery:=False
>     End With
> End Sub
> 
0
Utf
11/25/2009 4:21:02 PM
Reply:

Similar Artilces:

data input in text box
We have a form which the operator enters data in a text box. Currently we have a 'done' button on the form that the operator clicks to send the text box info to a vba program. How can we send the text box info to the vba program when the operator hits the enter key @ the end of the data entry for the text box? TIA -- _______________________________ In Christ's matchless name ted & colleen n6trf kc6rue Use the control's AfterUpdate event. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "ted" <n6trf@arr...

Transferring over outlook data to new XP machine
How do I transfer over my old emails, address book to my new XP machine? I have looked over the internet and found nothing the tells me EXACTLY how to do this, any help would be greatly appreciated. senior_tech@yahoo.com If your using MS Outlook copy your .PST file across and import it into the new install. >If your using MS Outlook copy your .PST file across and import it into the new install. No, don't import it. Simply use "File">"Open" -- Brian Tillman Smiths Aerospace 3290 Patterson Ave. SE, MS 1B3 Grand Rapids, MI 49512-1991 Brian.Tillman is the nam...

How do I use a "subtract" function in Excel?
Hi Kelly if you want to subtract the value in B1 from the value in A1 and have the answer display in C1 then in C1 type =A1-B1 Hope this helps Cheers JulieD "Kelly" <Kelly@discussions.microsoft.com> wrote in message news:5DF4C83F-6BF1-40A8-BC8A-692058A5C70B@microsoft.com... > ...

Conditional formatting macro
Help. I would like to know if it is possible to have a macro that changes the colour of a cell dependant on the number or text within. eg If the following cells were populated as follows a1=1 Make the cell Green =2 Make the cell Red =3 Make the cell Blue =4 Make the cell Orange and so on till 7 Is this at all possible ? I know that i can colour cells 3 times with simple conditional formatting, but would like to run upto seven different colours. any help would be appreciated. Steve '----------------------------------------------------------------- Private Sub Worksh...

Excel 2007
When I select cells to copy as a picture in Excel 2007, the resolution is terrible. Text and objects with shadow's are very blotchy when pasting the picture. How do you change the resolution of a 'Copy Picture'? ...

Input Excel 'Password to Open' through control in access form
Hi All, We know,Excel has prompt password to open it files. Is it possible to create a code that can supplies the excel prompt password?.So that when we open the excel file through our access control in a form, the excel files can be opened automatically.But when the excel files opened from its default icon,it will prompt a password first. ...

Parsing data from one spreadsheet into another format
The data that we dump out of one machine comes in like below. %AT_1300 Bottoms|Conductivity| (Water Out) InputRange VDC1to5 %AT_1300 Bottoms|Conductivity| (Water Out) Custom_Range_Low 0.0 %AT_1300 Bottoms|Conductivity| (Water Out) Custom_Range_Hi 0.0 %AT_1300 Bottoms|Conductivity| (Water Out) MinScale 0.0 %AT_1300 Bottoms|Conductivity| (Water Out) MaxScale 20.0 %AT_1300 Bottoms|Conductivity| (Water Out) EngUnits mhos %AT_1300 Bottoms|Conductivity| (Water Out) StepResponseTime 1.0 %AT_1300 Bottoms|Conductivity| (Water Out) DigFiltTimeCnst 0.016 And I need to convert this data to this f...

Compare records in a query then write equation??
Hi all, i have a problem and i need help, the case is as follows: the default rule is that i have 4 fields, (Date, Team, Score). each team is allowed to have one score per day but sometimes it can have 2 scores per day, when this is the case i wanna multiply each score by a certain number and have one score instead of 2 scores (similar to average but not average). So, i need to have a condition which compares records, and if this is the case, formulates this equation and gives me one score instead of 2 scores. Please help SELECT Team, [Date], Sum(Score)/Count(Score) * IIF(Count(Score) =1,1,S...

Excel not Access
I have designed an Access database that holds records relating to my stores audit results going back for about 5 years plus a load more information relating to these stores. This was used to produe a pack once a month, however a change in senior management means that I have got to shelve this and prodce a similar pack in Excel. The idea would be that the user could select a month or a 12 mnth date range that would produce data that could then be used to populate a number of excel templates that have been designed. Having not used excel for years I would be grateful for any suggestion...

How to keep format when importing Excel into SQL.
Can anybody help me please? When I import Excel file into SQL, a field that formated as 0000000000 (custom), loosing leading zeros. I tried to change data type in SQL after importing. No luck. I appretiate any help. See if using IMEX=1 helps: http://pratchev.blogspot.com/2007/10/importing-excel-data-into-sql-server.html -- Plamen Ratchev http://www.SQLStudio.com Plamen, I tried this, but got an error: "The OLE DB provider "Microsoft.Jet.OLEDB.4.0" has not been registered." Thank you very much for looking into this. "Plamen Ratchev" wr...

Auto-format in Microsoft Excel.
Each time i try to enter a number range, for example, 8- 10, in Excel, it constantly re-formats it to a date. If I change the formatting to "General" it turns it into a random number, usually 38209. I would like to turn off ALL auto-formatting, but that's probably asking too much. How do I disable this frustrating feature? thanks. Hi Paul When you enter "8-10" in a cell, that's not strictly a number but Excel thinks you mean a date so converts it as such. A date is a number and in your example the number 38209 represents August 10 2004 which is not a ra...

Exchange 2003 new install can not receive external email.
I have just setup a new Windows Server 2003 standard edition with Exchange 2003 standard edition on it. I have been working for a while trying to get it to receive external email. I can send out and send/ receive internal messages, but when someone trys to send me a message from outside our network they get the following returned mail message This Message was undeliverable due to the following reason: Each of the following recipients was rejected by a remote mail server. The reasons given by the server are included to help you determine why each recipient was rejected. Recipient: <**...

MS Money 95 data files
I hope that some one can answer this for me. I have used MS Money 95 for years, and it works just fine for me on Windows XP, however, I now have to reformat my hard drive, and have discovered that I can nolonger find my original install disk. Will the latest versions of Money still read the MS Money 95 data files. All that I have ever used the program for is to track my investments, and am unlikely to do any different in the future. Thanks Stan B In microsoft.public.money, Stan Banner wrote: >I hope that some one can answer this for me. >I have used MS Money 95 for years, and...

HELP! Need to export hourly sales data on POS (NOT RMS)
How can I export hourly sales data across a date range? For instance, I want to show hourly sales for the month of October so I can graph it and post it in our break room. If I can't export hourly data, can I export daily sales? The built-in reports don't address this data format. This is a multi-part message in MIME format. ------=_NextPart_000_008E_01C826DC.CBC512D0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit Mark, This should work for you. Keep in mind it takes up to 5-10 minutes to load...

How to change font size on formula bar in Excell 2007
I don't find Tools>Options>General (as suggested in other post answers) in Excel 2007. On the Office button there is an Excel Options but it doesn't provide a method of changing font size on the office but. My font is so small I can barely see it. Office button>ExcelOptions>Popular tab>in the "When creating new workbooks" section, choose font and font size -- Kind regards, Niek Otten Microsoft MVP - Excel "jimwillie" <jimwillie@discussions.microsoft.com> wrote in message news:588AAC05-0F52-404E-AA01-128E70E02D0B@microso...

Radar chart in Access 2007 report
Can you add a Radar chart to an access 2207 report? ...

Opening Excel Workbooks
I'm running into an issue where if I click on an Excel file through My Documents, it doesn't automatically bring it up. I get the toolbar but the actual spreadsheet doesn't appear on the screen. I have to click on the taskbar to get it to pop up. If I already have Excel active and I open a file through Excel, this doesn't happen. Any ideas? Here is a similar thread: http://www.excelforum.com/showthread.php?s=&threadid=237195 Rolli -- Message posted from http://www.ExcelForum.com Hi, Take a look at Tools-Options-General tab- uncheck ignore other application...

Unexpected error message on closing an Excel file
Suddenly I am getting the following message when I try to close a workbook: "Your formula contains an invalid external reference to a worksheet. Verify that the path, workbook, and range name or cell reference are correct, and try again" The mysterious thing is that it does not happen consistently and that, after I click OK after the above message, I can still save the file. What might be the cause of this error message and can the "invalid reference" be tracked down using one of the utility add-ins such as J. Walkenbach's PUP? If it only happens when you close ...

Strange Access Denied Problem with Windows 7
I got a new computer about six months ago that came with Windows Vista Home Premium 64bit. Before that I had done all of my .NET development either on an XP Pro VM or my former XP Pro computer at home. Shortly after getting my new computer at home, I also got a license for VMWare to be able to test my software on multiple platforms and configurations. I had wrote an application originally in VB.NET that was a simple backup utility. It supports mutiple backup configurations. Any given copnfiguration would define a backup which would be a list of files to backup, a list of folders to ...

help with simple maths in excel
I want to do a simple arithmatic excercise in excel for my grand daughter. It is stuff like 2+2 =4 Smart me has hit a problem at the first hurdle... I need to put 2 in one cell the + in another cell and then 2 in another = in another and then she puts the answer in the next one. So the above would have 4 cells completed and she would put the answer in the 5th one. When I use the + or = sign in a cell of its own it (excel) thinks I am doing an equation, is there a way around this? I will work on the answer like if she gets it correct or wrong how I will do that...a sound or som...

adding name /creating field/query?
Hello, I can create an invoice_number field in a query using the primary field ID from the main table as invoice_number: ID but if ID say is 100, I cannot work out how to create renewal_invoice_100 Cheers Geoff Geoff We aren't there. We can't see what you're looking at. Where did "renewal_invoice_100" come from and what does it mean? Please post the SQL statement of the query you are trying to use. -- Regards Jeff Boyce www.InformationFutures.net Microsoft Office/Access MVP http://mvp.support.microsoft.com/ Microsoft IT Academy Program Mentor http://micro...

Personal Macro Workbook
I had some macro stored in the personal macro workbook but now I can not find the workbook. When I try to do a new macro and store it in the "Personal Macro Workbook" I get the error message "Personal Macro Workbook in the startup folder must stay open for recording". I click ok and get a message that I'm unable to record. I can record macro to other workbooks. What happened to the personal macro workbook ? Thanks ...

Sorting Data #5
Is there formula or anyway to be able sort the below data into a format that I could create a pivot table on? I spend to many hours doing this every month. Invoice #: 12345 Invoice Date: 1/16/1950 A/P Code: ABC Due Date: 1/16/1950 Total Payable: $100.00 Reference: Freight: Account #: 1234 Description: Name Reference 1 Amount: $100.00 Account #: 4321 Description: Name Reference 2 Amount: $100.00 Account #: 9876 Description: Name Reference 3 Amount: $100.00 Any help would be much appreciated!! You need to show a Before and After version. You still might not get any help, but your ...

How To Copy MS Word mailing labels into Excel
I have a word doc that I want to put into Excel. I want to add some more fields to the names and addresses. Is this simple or do I have to learn how to program? Michael Rodriguez City of Grand Prairie Michael, have you tried to copy and paste the data into excel? -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2000 & 97 ** remove news from my email address to reply by email ** "Michael Rodriguez" <mrodrigu@gptx.org> wrote in messa...

Importing leads and workflow
We are just implementing CRM and have a couple of lead lists that we want to import (about 5000 records). The sales force would like calls automatically scheduled when the list is imported and would only like 50 calls scheduled per week. I know that I can assign leads based on various criteria to the correct salesperson. However, is there any way that I can create the phone activities and only limit to 50 per week? Does workflow look at the salesperson work schedule at all or will each sales person have 1000 phone calls scheduled for 3 days from when I import? There isn't anything in ...