Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a report for yesterday's date. 1

Status
Not open for further replies.

ThornPCC

Programmer
Jan 6, 2000
26
0
0
US
Hello,<br>
<br>
I know this may be a simple thing, but the method is escaping me. I have to run a report for our Payroll Clerk at or around noon every weekday. This report calculates pagecounts for the previous day. For now I have the report ask me for the pagecount date. This is ok, but I'd like to automate the whole thing. The intire process is as follows;<br>
<br>
1. Delete old pagefile table.<br>
2. Import pagefile.DBF file from network directory. <br>
3. Run query to select records from previous day. <br>
4. Print Page Count report and turn into Payroll Clerk.<br>
<br>
I've tried setting the criteria in the query using the DateAdd and Date() functions, but keep getting blank results. Any ideas? Unfortunately I won't be able to try them until I get back into work on Monday.<br>
<br>
Thanks. <p>Phil<br><a href=mailto: > </a><br><a href= > </a><br><br>
Most of us go through life not knowing what we want, but <br>
but feeling damned sure that this isn't it.<br>

 
Use the DateAdd function. Yesterday's date is DateAddd(Date,-1)<br>
Therefore you want to create your SQL string and set the RecordSource of the report.<br>
<br>
So, before opening the report set a global variable ( I like to use strSQL ) like so<br>
<br>
strSQL=&quot;SELECT Field1, Field2,DateField &quot;<br>
strSQL=strSQL & &quot;WHERE DateField=#&quot; & DateAdd(Date,-1) & &quot;#;&quot;<br>
<br>
And in the open event of the report<br>
<br>
Me.RecordSource=strSQL<br>
<br>
Hope this helps<br>
<br>
WP <p>Bill Paton<br><a href=mailto:wpaton@neptune400.co.uk>wpaton@neptune400.co.uk</a><br><a href=
 
To automate the whole thing is going to require a VBA function.<br>
Are you good at VBA code?<br>
The functions parts are<br>
Take a look at the &quot;Docmd&quot; function in Help<br>
Also type &quot;DOCMD.&quot; and a list will come up with all of the Docmd options<br>
<br>
1. What is the page file? a file on the hard drive?<br>
Kill deletes files on the hard drive<br>
Kill &quot;C:\myfile.txt&quot;<br>
or<br>
docmd.deleteobject deletes Access items such as tables etc.<br>
DoCmd.DeleteObject acForm, &quot;Myform&quot;<br>
<br>
2. Import .DBF file<br>
DoCmd.TransferDatabase acImport, &quot;dBase III&quot;, &quot;C:\MydBase.dbf&quot;, acTable, &quot;Source&quot;, TableName<br>
You can import all 3 dBase types dBase III 'dBbase IV 'dBase 5 here are their spec names<br>
<br>
3. Run query<br>
I think if you make a report you don't need a separate query as you mentioned.<br>
The Reports recordsource is in fact the query<br>
<br>
4. Report <br>
Again &quot;Docmd&quot; comes to the rescue<br>
DoCmd.OpenReport &quot;Reportname&quot;, acViewNormal<br>
Will print the report out directly<br>
When you design the report, go to Page properties and pick the printer you want it to go to.<br>
When you save it, it will always go to that printer.<br>
<br>
Now to put the whole thing together<br>
Create a Macro and name it autoexec<br>
It will have 2 events.<br>
1st &quot;Runcode&quot; put name of your function you created above such as &quot;RunPayrollReport ()&quot; It must be a 'function' and not a 'sub' or it will NOT show up in your macro.<br>
2nd &quot;Quit&quot;<br>
<br>
so when you open the Access database it will <br>
1. delete the &quot;Page file&quot; <br>
2. Import the dBase file<br>
3. Print the report<br>
4. close back up<br>
<br>
now while you debugging it<br>
If it dose not work properly Press &quot;Ctrl&quot; &quot;Break&quot; keys to stop it.<br>
If you pull this off you will have reached &quot;guru&quot; status in Access. Ha <br>
No, it is do-able if you take it one step at a time.<br>
<br>

 
DougP,<br>
<br>
I just wanted to say that I am impressed at the detail you have given in response to ThornPCC's question. I have allready copied your response for my own future reference. Thank you for the great tip :)<br>

 
WP & DougP,<br>
<br>
Thank you bot for your answers. I will be combining them both into my report. Together you've both answered my qusetion. I'm glad I found this site.<br>
<br>
<br>
<p>Phil<br><a href=mailto: > </a><br><a href= > </a><br>Most of us go through life not knowing what we want, but feeling damned sure that this isn't it.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top