MS Access reports issue? - vba

I have an already existing report that runs off a particular query. This report runs perfectly. I was having an issue with one of the CLIENTs for the report, where I had to change a small piece of information. This required me to run some VBA code and insert all the info into a temp table. I'd like to run the same exact report, however, instead of using a query, to use the tempInfo table. Is there a way for me to do that? it's okay if I create another report, but the first report is somewhat complicated - so it would save a lot of time if I could just copy and paste at least the GROUP, SORT TOTAL so my data is displayed correctly. ANy suggestions?

Copy the report that you are wanting to use and paste it in the navigation menu to create a copy of it.
To use the "Temp Table" in your report, just go into design view of the newly copied report and change the Record Source to your "Temp Table."
You may also need to change the control source of any textboxes, labels, etc..

Related

Running SQL on Excel like Query on Google Sheets

I have a large database on Microsoft Excel 2010 on which I want to run SQL queries like the =QUERY formula in Google Sheets.
Basically on Google Sheets, the =QUERY can reference cells which take user input. This allows me to dynamically update the table based on the user input fed into the =QUERY. I've created a Google Sheet exemplifying what I mean here (please change cell G3 only) - the only difference between this and the final product would be that the complete table is in a sheet and the dynamically updated one is in another.
I've created a connection in Data Wizard in Excel but it doesn't seem like I'd be able to take user input running queries from there. Also, I've found similar questions here but neither provided an answer to this question specifically.
I want to do the exact same thing on Excel - being I do not want to use VBA, Filters, etc. I want precisely this. Is there a way to do this?
EDIT: I've tried Advanced Filters but they don't respond dynamically to different user input: you input once, it gives you the result, you go back and change parameters and it doesn't change it again.
You can use POWER QUERY for Excel, Info, Download.

Can Powerpivot be used to present data without pivoting it?

This isn't a coding question, so much as it is a functionality question.
I'm a bit new to Powerpivot and I'm attempting to use Powerpivot as a way to deliver reports to my team rather than SSRS because in our company, the only SSRS ReportServer I can use is officially "owned" by a team that is hostile to my team.
I have written numerous SQL ad-hoc queries that we are using for reports in SSRS, but been I've trying to migrate them to Powerpivot. For some of the reports, I've been able to paste the SQL query into the powerpivot window and make a pivottable out of these. However, I'd like to be able have some workbooks just contain the results of the query (they don't deal with numbers, as some of them are a data dump or a large collection of text strings), so that they look like the powerpivot window's dataset, but that they can be filtered, sorted, etc. Is this possible, or can I only use pivottables? I can't seem to find a way that I can just get Excel to directly display what is in the Powerpivot window without pivoting it - I know it is called Power*pivot* but because the PP window just shows the query results itself, I'm hoping there is a way to use it as an alternative to SSRS.
Also is there anyway to check if our Sharepoint server is capable of running Powerpivot so that I can deploy reports there for users to use without having Powerpivot installed on their computers other than by saving it to Sharepoint and seeing if a user can run it? If not, how difficult would it be to have an IT team update the SP server so that it can handle PP?
Any help is appreciated, as I'm in a position where I cannot contact IT or project management, and I can't raise any red flags with IT/BI/PM. Thank you very much for your time.
It sounds like you just want to get the results of your SQL query directly into an Excel spreadsheet, where you can use the Excel filter and sort capability. It doesn't appear that you want to use any of the functionality that PowerPivot provides, so you can achieve what you described by using an existing Excel component, Microsoft Query. It's a bit of a clunky old interface but it works. Here's some instructions to use:
In an Excel spreadsheet, click on the Data tab, select the "From Other Sources" button on the Get External Data area of the ribbon.
Select "From Microsoft Query"
On the "Choose Data Source" click OK to create a new data source
On the "Create new data source" window select the appropriate driver and database details for your data source
If using a SQL Server data source, don't select anything for the optional step 4 (select a default table).
Click OK to return to the Choose Data Source window, then OK again to select the new data source.
You're now prompted to choose columns for your query, but if you already have some SQL then click Cancel - this will display a prompt to continue editing in Microsoft Query - click Yes.
The Add Tables window pops up, click Close
You're now in the Microsoft Query interface. If you click on the SQL button, you can paste in your SQL. Click the Return Data button to run the query, the results will be displayed in an Excel worksheet.
Once this is set up, you just need to click "Refresh Data" on the Data tab to re-run the query and update the spreadsheet.

Crystal Reports vs. SQL Queries

I'm a programmer (mostly C++) who has moved into a non-software workplace. However, I don't have much experience with database stuff at all.
TL;DR: If we compare Crystal Reports to just writing scripts that execute SQL queries and parse the results, is there anything that CR can do that isn't possible via SQL queries & scripts? I'm talking purely in terms of extracting data - not making pretty documents.
Detail:
At my workplace they have a process where you run a bunch of Crystal Reports, modify the date range to the current month, manually export each to excel, delete the rows and columns that aren't needed, and then cut and paste into a summary excel document that is used by management.
To me, this is pretty crazy and stupid. I'd like to automate/script most of it.
So I have two options:
Learn Crystal Reports and try to modify the existing reports to be more automated.
Dump CR and just learn SQL and do the whole thing programmatically with scripts working with CSV files or something.
I'd much rather learn SQL since it's more general and useful. But I need to be assured that I can get the data output that I need (without writing a million lines of code to reproduce CR myself.)
So yeah, I'm looking for an answer like, "The two are equivalent. Anything you can do in CR you can do easily via scripts and SQL," or "If you need to group records into categories based on a parameter and then sum their one of their fields, then CR will do it much more easily than raw code," to push me in one direction or another.
Edit:
Some additional detail. At the moment my crystal reports run a database query, and then crystal does things like, "don't display the records that are returned, instead group the records by Field A and then display the count of how many records in each group."
Is functionality like this difficult to reproduce via SQL coding? I wouldnt want to have to write a python (or whatever) script to parse and manipulate the data from plaintext CSV, for example.
You can't just compare SQL and CR - they have different purpose. SQL (in this context) is data source, CR is pretty output formatter. For excel you would need data, not formatted output. Excel combined with SQL can give you all CR options (dynamic crosstab reports, charts etc) what you can't get directly from SQL data.
BTW, creating SQL views or procedures is often needed to overcome CR limitations; from this standpoint SQL has lot of more options than CR.
I personally would go with SQL+Excel route. In our company we're using simply SQL+CR without postprocessing, sometimes SQL+Excel. Our customers are using different approaches.
But like said by other people, choice of tools depends on more things. Who has to redesign reports? Who will maintain these reports? How often requirements change? Are there more uses for CR reports besides sourcing Excel tables? Who will be waked up at night, if reports do not work?
Management perpective:
In many I will say mostly cases management does not know SQL. So if a manager for E.g.HR wants to know staus about something then how he will get that status?? This is where Crystal reports come into picture, Using crystal reports they do not have to worry about SQL; they will just enter required fields and get their data.
Programmer perspective:
Simple data outputs can be achieved through SQL but consider a scenario where you need to pull details as well as summary. I agree it can be done via SQL but consider the overhead of time and proficiency required to develop such output using sql. I bet it wont be that easy to develop such output using sql as compared to crystal. So I will say learn both SQL and crystal, you will get to choose the tool to apply for your requirement.
You can write SQL and drop it into the Crystal Report. Best of both worlds, and possibly faster performance than the drag-and-drop Crystal functionality.
You will see some response time lag when the report runs.
There are actually a few things that Crystal Reports can do that are very tricky using plain SQL Queries as Crystal Reports can access the entire dataset in a single formula and can do things at runtime.
However unless you have some really crazy complex Crystal Reports I would recommend building a tool in Excel that can one click the info straight into a new sheet.
I did this and it got me a promotion, not kidding :P
I have a custom Excel Addin I can give you code to that basically does this:
On open, connects to the database and downloads a list of menu options connected to views and procedures
Adds these menu options into a new Ribbon tab within Excel
When one is clicked, runs the view and dumps the entire dataset (properly formatted) into a new sheet
Advantage of this is you can update the main menu list and each view it references without making any changes to the file or re-issuing anything to everyone.
Crystal could be helpful if you want to create a document with a specific layout , logos etc. and show some data on it. Export to excel from Crystal repot is not easy - usually there are a lot of empty columns and rows and each report should be tweaked to avoid that.
If you need to export some data from a SQLServer database to excel your best option will be SSIS ( I guess you have a license for SQL Server). If you don't have license for SSIS or you are using for example Access database there are also some inexpensive tools, which can retrieve data from any database ( not just SQLServer) and export it to excel. I would suggest you to check this one: http://www.r-tag.com. It can run Crystal reports and SQL reports so you can start using your crystal reports immediately and start transforming them to SQL reports whenever you have time for that. Both reports could be exported to excel.
i fixed this by editing excel sql, Left(Column_maxLength, 250)
this resolved my issue
in my case if even if i read left 250 character is enough

extract raw SQL query from a Crystal Report .rpt file

I've got an .rpt file that I did not write and can find no documentation about. I want to be able to review the SQL that is generated from this report so that I can figure out, well, what data it was pulling and what WHERE clause parameters were used.
I can open it up and see the report layout. But when I select Database|Show SQL Query... the report tries to connect to the data source. The problem is, the data source being used is unknown to me, probably an ODBC connection used by whoever wrote the query. All I can do at that stage is 'Cancel' and I'm back to looking at the report designer.
Am I missing something? Can I get to the SQL query without connecting to the datasource? It seems like viewing the selection criteria shouldn't be dependent on a data connection.
Thanks.
version: Crystal Reports 2008
I know that this is an old thread, but I encountered this same problem. Effectively we used to have a database/application that has since been aquired by an external agency.
Although they now have the database/application they don't have access to crystal reports, so we can't just send them the old report that we used to run. Likewise we can't run it as we don't even have the database set up anywhere.... So instead our plan was just to extract the SQL code generated by the report and forward that on.
We experienced the same problem, but the solution is actually pretty simple.
If you don't have access to the original data source, just create a new 'blank' datasource (such as an ODBC connection). As long as the connection to the datasource works (i.e. it is some kind of valid datasource this it works fine). When running the 'Show SQL' option point the report to this datasource. As long as you don't try to actually run the report (and only show the SQL) the operation wont fail. This worked for our situation anyway. (Crystal Reports 2008)
(I can give more details if it helps in any way.)
It should be possible to find out some details about the existing datasource, by selecting Database > Set Datasource Location... .
As well as enabling you to change the datasource location, this should show you some information about the current datasource, such as which type of datasource is being used, and possibly (dependant on the type of driver) the name of the database. It is likely to be less helpful if (as you surmise) the datasource is ODBC, but if it uses a native driver there may be something useful.
Without the password, I'm not sure how much you can do. It seems "Show SQL Query" requires to report to run first, then generate the SQL plan.
It's not ideal, but you could go to Database > Visual Linking Expert to at least see the tables and how they are joined, and the go to the Record Selection Formula Editor and see what the custom WHERE statements are.
Viewing the SQL of a Command in a Crystal Report File
There are times you have just the report file, but not the associated database structure that the report uses.
This is common when dealing with example reports of functionality you wish to mimic.
This is a workaround ONLY to allow you to see the SQL of a Command that a Crystal Report is based on, when you don't have the underlying database connection that the report is based on.
In essence, the dialog box has to be satisfied before it will show the SQL, so we fool it with a legitimate Data Source, just not one that would work with the SQL that is actually in the SQL Command.
Why does a report use a command? Doesn't Crystal Reports have the ability to link tables?
When a Crystal Report is based on a record set that is too complex for the table linking functionality within Crystal Reports, the report can instead be based on a SQL Query, usually developed/tested in another editor tool and pasted into the command. This allows advanced SQL functions to be utilized.
If you don't already have a Data Source on your computer set up that you can connect to, you will need to build one first.
A simple Microsoft Access .mdb file saved in a simple location will suffice.
I placed mine with the path C:\A_test\test.mdb to make it easy to find.
If you don't have one, google for a sample mdb file and download it, saving it with a name and location you can remember. (You won't ever actually open this file, but just connect to it.)
Once you have the file saved, open the ODBC Administrator and create a New Data Source.
(you can get to the ODBC Administrator quickly from Start > type ODBC in the Search)
On the User DSN tab, click the Add button.
Scroll down the driver list to Microsoft Access Driver (*.mdb), select it and click the Finish button.
In the Data Source Name box, type a name (I used MyTest).
Click the Select Button and select the mdb file you saved from a previous step, click OK.
Click OK again. You will see your new Data Source listed by the name you gave it. Click OK.
You now have the data source you will need for the next steps.
Open the Crystal Report you want to see the SQL command for, and click on Database Expert button or Database>Database Expert Menu.
Under Selected Tables, right click on the Command and choose View Command
The Data Source Selection Box appears. Select the Data Source you created (or one you already use) and click the Finish button. The View Command box should open with the SQL in the left pane. Copy the SQL into your favorite text editor.
Whats happening is that the crystal reports needs a database to connect to regardless if its the original source DB or not.
Create a local database or use a database stored on a server, added it to your ODBC Datasources and use it when connecting. After a successful connection you should be able to view the SQL query without an error.

Generate Reports from Ms Access 2007 Using Queries automatically via VBA

I have a few queries which need to be exported into a report and I want this to be done automatically each time the database is opened. I'm guessing this would be possible using VBA to which i dont have much knowledge off.
Can anyone help with this please?
Thank You
The easiest way would be to build a report based on the queries and add an Autoexec macro to the database to print the report.
EDIT
Choose Create Macro, select Open Report as the Action, select the report name from the dropdown list, save the macro as AutoExec.
Maybe I'm missing something in your question but it sounds like you just need to base the report's record source on the SQL and don't need VBA. Copy and paste the SQL directly into the report record source. Every time you open the report it will automatically pull the most recent data.