I have a query (with calculated fields) in Access (2007) and the data changes depending on the dates and staff person selected. I need to produce a series of graphs based on the data in this query and it seems to me that Excel is far easier to create graphs than Access.
When I use the Get External Data feature of Excel and the dialog box with the tables and queries appears, the query I need is not listed. Is this because the query has calculated fields or some other reason? I can find the underlying table but then the data is not filtered and of course, there are no calculated fields.
I believe connections can be made using vba but I have no idea of how to do this.
This is my sql for the query if that helps. - SELECT tblStaffPerformanceStats.SRID, tblStaffPerformanceStats.RYear, tblStaffPerformanceStats.StaffCode, tblStaffPerformanceStats.PercentageRate, tblStaffPerformanceStats.ChargeRate, tblStaffPerformanceStats.WkDays, tblStaffPerformanceStats.MaxBillableHrs, tblStaffPerformanceStats.ActualBillableRevenue, tblStaffPerformanceStats.ActualBillableHrs, tblStaffPerformanceStats.HrsWrittenOff, tblStaffPerformanceStats.HrsWrittenBack, tblStaffPerformanceStats.HrsNonAttendance, tblStaffPerformanceStats.HrsOfficeAdmin, tblStaffPerformanceStats.HrsProfessionalDev, tblStaffPerformanceStats.HrsFirmDev, [WkDays]*DLookUp("[DailyAttendHrs] ","[tblStaff]","[SCode] = '" & [Forms]![afmStaffReviewCentre]![cboLastname] & "'") AS MaxAvailableHrs, ([WkDays]*DLookUp("[DailyAttendHrs] ","[tblStaff]","[SCode] = '" & [Forms]![afmStaffReviewCentre]![cboLastname] & "'"))*[ChargeRate] AS [Max$], [MaxBillableHrs]*[PercentageRate] AS TargetedHrs, Round(([MaxBillableHrs]*[PercentageRate])*[ChargeRate],0) AS TargetedRevenue, [ActualBillableHrs]-[HrsWrittenOff]+[HrsWrittenBack] AS ActualRecoverableHrs, [HrsNonAttendance]*[ChargeRate] AS [Non-Attendance$], [HrsOfficeAdmin]*[ChargeRate] AS [OfficeAdmin$], [HrsProfessionalDev]*[ChargeRate] AS [ProfDev$], [HrsFirmDev]*[ChargeRate] AS [FirmDev$], [ActualBillableRevenue]+([HrsOfficeAdmin]*[ChargeRate])+([HrsFirmDev]*[ChargeRate])+([HrsProfessionalDev]*[ChargeRate]) AS Total, Format(DSum("[ActualBillableHrs]-[HrsWrittenOff]+[HrsWrittenBack]","qryStaffPerformanceCalculator","[SRID]<=" & [SRID] & ""),"000.0") AS ActualHrsCumulative, Format(DSum("[TargetedHrs]","qryStaffPerformanceCalculator","[SRID]<=" & [SRID] & ""),"000.0") AS TargetedlHrsCumulative, Format(DSum(" [ActualBillableRevenue]","qryStaffPerformanceCalculator","[SRID]<=" & [SRID] & ""),"000.0") AS ActualFeesCumulative, Format(DSum(" [TargetedRevenue]","qryStaffPerformanceCalculator","[SRID]<=" & [SRID] & ""),"000.0") AS TargetedlFeesCumulative, [ActualBillableRevenue]+([ChargeRate]*[HrsNonAttendance])+([HrsOfficeAdmin]*[ChargeRate])+([ChargeRate]*[HrsProfessionalDev])+([HrsFirmDev]*[ChargeRate]) AS TotalAcual
-
FROM tblStaffPerformanceStats
-
WHERE (((tblStaffPerformanceStats.RYear) Between #7/1/2008# And #6/30/2009#) AND ((tblStaffPerformanceStats.StaffCode)=[Forms]![afmStaffReviewCentre]![cboLastname]))
-
ORDER BY tblStaffPerformanceStats.SRID;
NB: The date range is currently hard coded but eventually will be selectable when everything is working how I want it.
I would appreciate suggestions on how to set up a connection between excel and my access query and if vba is the way to go, some sample code I could adapt.
I should also mention that although I am using Access 2007 and Excel 2007, the end user will be using Access 2007 runtime and probably Excel 2003.
Thanks
Feb 9 '09
15 5259
Thanks again for your suggestions
This is what I have tried:
In a module - Function TDXLOut(sql As String)
-
CurrentDb.QueryDefs("MyQuery").sql = sql
-
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "MyQuery", "C:\ExcelTest\book1.xlsx", True
-
End Function
Attached to a button - Private Sub Command4_Click()
-
Dim strSQL As String
-
strSQL = "SELECT tblStaffPerformanceStats.SRID, tblStaffPerformanceStats.RYear, tblStaffPerformanceStats.StaffCode, " & _
-
"tblStaffPerformanceStats.PercentageRate, tblStaffPerformanceStats.ChargeRate " & _
-
"FROM tblStaffPerformanceStats " & _
-
"WHERE (((tblStaffPerformanceStats.RYear) >= (DMax('[RYear]', '[tblStaffPerformanceStats]') - 366)) " & _
-
"And ((tblStaffPerformanceStats.StaffCode) = Forms!afmStaffReviewCentre!cboLastname)) " & _
-
"ORDER BY tblStaffPerformanceStats.SRID;"
-
-
TDXLOut (strSQL)
-
End Sub
I get this error:
Runtime error 3265
Item not found in this collection
Do I have to select a reference to make this work?
Then I tried this: - Function OTXLOut(sql As String)
-
CurrentDb.QueryDefs("MyQuery").sql = sql
-
DoCmd.OutputTo acOutputQuery, "MyQuery", acFormatXLS, "C:\ExcelTest\book1.xlsx"
-
End Function
and called it using a similar snippet of code to the first one.
I get the same error message.
Dim db As DAO.Database
Stewart, I have already tried that after posting the original piece of code. It did not help.
ChipR 1,287
Recognized Expert Top Contributor
The runtime error you are getting says: "MyQuery" is not found in the QueryDefs collection.
mshmyob 904
Recognized Expert Contributor
First don't use reserved words like sql it can confuse things.
Try something like the following
button click code -
Private Sub Command4_Click()
-
-
Dim qdfTemp As QueryDef
-
Set qdfTemp = CurrentDb.CreateQueryDef("MyQuery", "your SQL code goes here")
-
-
' call your function
-
fExportExcel
-
-
End Sub
-
function code -
Function fExportExcel()
-
-
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "MyQuery", "c:\temp\test.xls", 0
-
-
' delete your MyQuery definition from your project
-
CurrentDb.QueryDefs.Delete "MyQuery"
-
-
End Function
-
Hope this helps
cheers, @OzNet
Mshmyob, your example is working and gives me something to build on. I really appreciate your help.
Many thanks
mshmyob 904
Recognized Expert Contributor
You're welcome. Good luck.
cheers,
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mark T. |
last post by:
Hi,
I've got a simple DB (Office Win XP Professional).
Basically, it's like a check book register - deposit, deduction and running
sum.
I'd like to somehow link it to an Excel spreadsheet that will do the
calculations and then keep the data updated in the form
and report in the DB. Apparently this isn't done in Access because
the "cell" where you enter the data is actually a field. I have a tabular
form that looks just like a...
|
by: AOstarello |
last post by:
Hi all,
I'm trying to link to some OLAP cubes that were created using the MS
SQL Server Analysis Tools. The cubes reside on an Analysis Server.
I'm trying to find a simple way for users to query the cubes without a
lot of programming overhead.
I can easily get the results I want by using MS Excel 2003. Through
the menus, I choose: Data > Import External Data > New Database Query.
Then I can select the OLAP Cubes tab, create a data...
|
by: chemdawg |
last post by:
Need help in linking access query to excel. The link I have now does
not updated my main table or reports. What am i missing here?
|
by: oyk |
last post by:
I hope someone could help me on this. I have linked an excel worksheet to
access but the some data shown in the access table has the #Num errors.
Presumably,
this must be because the data in the particular column in excel are of mixed
data-type. For example, there are numbers as well as texts like "abcd" etc.
in the same columns
I tried changing the cell format in excel to text but to no avail as the
problem still exist.
Really need...
|
by: jalmar |
last post by:
Hello again:
My second question is:
I am linking an excel spreadsheet into Access, I have it linked and at first had problems getting the information imported into Access-it wasn't importing-I had a msg in the populated fields which read #NUM- I was told to use quotations before and after the numbers in Excel and it would import correctly, which did happen but when I run my query off that linked table, it creates far too many...
| |
by: smaczylo |
last post by:
Hello, I've recently been asked to work with Microsoft Access, and
while I feel quite comfortable with Excel, I'm at a complete loss with
databases. If someone could help me with this issue I'm having I'd be
most appreciative. The database is already constructed, I'm just
wanting to export the data to an excel file.
In short, I'm hoping to export two Tables (or queries...not sure which
to use - they both seem to have the same data) in...
|
by: Andrew W |
last post by:
Hi All,
I'm trying to link to data on a website with Access. When I try File/
Get External Data/ link tables/ HTML/, I get the following error
message:
Database or object is read-only.
I find this odd because I can get this data thru Excel's web query
function.
|
by: karthik28 |
last post by:
I tried linking an excel spreadsheet to an access database. It shows me a window with the data but the header row in missing. However, when I open the excel file, save it without making any changes and try linking it again, it works fine.
Please suggest a solution so that I dont have keep saving the excel file before linking it.
Thanks
KS
|
by: agarwasa2008 |
last post by:
Hi,
I have a perfect file called "Products.xls" that I link to my MS
Access 2003 database and everytthing looks good in that file.
When I view the same file after linking in my database the data values
of records in "tblProducts" are incorrect. For example the tblProducts
has a field called "PackageSize" as listed below. THe problem is that
it displays the text correctly but if the field has numbers only it
messes it up. I have set...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |