I am using Access 2007. I want to use VBA code that will programmatically
run an Access Report a series of times. Something like this:
Dim eid$(5)
eid$(1)="001":eid$(2)="021":eid$(3)="043":eid$(4)="052":eid$(5)="067"
for i=1 to 5
Forms![frmWork]!txtEid=eid$(i)
DoCmd.OpenReport "rptEmployees", acViewPreview
next i
The report uses a query that contains:
WHERE (employee.eid)=Forms![frmWork]!txtEid
After the report appears on the screen I want it to immediately close - without the user
clicking Close Print Preview - and return to the VBA loop so another report can be generated.
You may wonder why I'm doing this? Let's just say I'm experimenting.
My question is...how can I get the report to close? Is there an event that occurs
when a report has finished printing?
If I knew how many records (n) were output by the query I could put a counter
in the report's Detail_Print() code. When the counter reached n I could have the report close.
Can I determine how many records are in the query results when the report opens?
Thanks very much.
Related
I am working on updating an Access database with this year's new data. I did not write the code that goes along with it, and am trying to find out where the formula is for an output (ratios) that the VBA code produces. Is there a way to trace back where the output came from?
I've tried just doing CTRL F to find the word "ratio" in the code but it's so long I can't pin down exactly where it's coming from.
No error messages
In debug mode you can step through the code step by step by pressing F8. You should be able to find the origin of every data export that way.
If the outputed data is a result of calculations I would check every query in the database. One of these probably takes care of those ratio's.
I have tried
ChosenOutputMethod := CustomLayoutReporting.GetExcelOption;
on the report but when I press preview, it doesn't export to excel. I want to achieve so that every time when run, the report is exported in excel document.
I want it to be in the report itself as of report 116 customer statement.
I don't want to use SAVEASEXCEL function
I'm afraid it's possible only using SAVEASEXCEL. Any reason why you don't want to use it?
You can also use the Excel Buffer to create reports in Excel directly.
Cheers
You need to press Print -> Microsoft Excel button.
Here is my scenario:
I am starting AutoIT recorder. I record using the keyboard since using the mouse causes the script to stop most of the time or does something inaccurate when started after that.
What I do is I open up an Excel template I have created. I then go into an ERP system and copy a few columns which I paste into Excel. After these columns are inserted, a few more columns are calculated from the formulas I have previously inserted.
The problem is that when I am into the ERP system I have selected a specific time period...Let's say 1st November till 31st November. I then save the excel and use the Excel option to send an email to specific people with the excel report attached.
I compile the autoit script to an exe and I have a scheduler which starts the exe. The problem is that I need a way to change the date to December, then January and so on... How do I do that using AutoIt? Can it be done at all?
This is how the date looks like in the ERP program:
You need to first inspect the program using AutoIt Window Info tool: drag the target icon to the filed you wish to click on - use ControlClick. Let's take an example with Excel, it says the title is: "Book1 - Excel" and the ID of the button I chose is "1001", the script will be:
ControlClick("Book1 - Excel", "", 1001)
If there isn't any ID, it will be harder as you'll need to MouseClick by coordinates which is prone for errors...
Changing the time: in order to change the date picking according to the current month you'll need something like:
Local $stringInCell = ControlGetText("ERP title", "text in ERP window (can be empty)", controlID)
If #MON = StringLeft($stringInCell, 2) Then
ControlClick("ERP title", "text in ERP window (can be empty)", controlID)
EndIf
Where #MON is a macro, and StringLeft is like starts with, assuming the first 2 characters are good for you (e.g. January is 01).
I am creating a form in MS Access that exceeds 22 inches in length. This form is extremely long so I am using tabs to spread out the questions.
I've now copied the form (with the tabs) on to a report in order to filter the data and to print it.
The name of the Tab control on the report is 'TabCtl219' and the report name is 'rpt_ADMIN'. I'd like to write some vba to print page 1, page 2, and page 3. Considering I can manually flip through the pages on the report, i'd like to print each page using vba. Currently, it will only print page 1.
Your thoughts are greatly appreciated.
One possible solution would be to get rid of the tab control and spread out the ui-elements and information over several pages.
I call an Access macro from vb.net like so:
Acc.DoCmd.RunMacro("Macro1")
The Macro in Access has many OpenQuerys and Msgbox with a message saying "data done" at the end.
When I execute the macro from vb.net, it shows the data done message and then done. However, when I analyse the table's to see if data has been appended, it hasen't.
When I run the same macro from within Access, it works fine. It does show many messages like "You are about to run an append query that will modify data in your query" and I hit yes and does take slightly longer, but it does do it.
In VB.NET, the only message I get is the final messagebox.
I have also tried:
Acc.SetOption("Confirm Action Queries", 0)
Acc.SetOption("Confirm Document Deletions", 0)
Acc.SetOption("Confirm Record Changes", 0)
before executing the macro from within VB.NET but to no avail. Still works the same.
Is there a way to fix it?
EDIT: My Access DB is mdb file
I think the problem is with the UI messages in the macro:
It does show many messages like "You are about to run an append query that will modify data in your query" and I hit yes
There's an option in Access to suppress these confirmation queries, you'll want them suppressed in the .mdb file. Looks like attempting to suppress them from VB isn't working.