Thread: Access
View Single Post
  #9  
Old May 7th, 2010, 09:43 PM posted to microsoft.public.access.gettingstarted
PieterLinden via AccessMonster.com
external usenet poster
 
Posts: 307
Default Access

bcraigmiles wrote:
No one will be opening the report but me, but each time I open it, something
is altered because end-users are constantly putting in data. I need to
number the report each time I print it.

As Ken points out, it will be up to you to determine what constitutes
"running a report". For instance, if someone tries to print a report but

[quoted text clipped - 12 lines]
I would like to consecutively number an Access report each time it runs so
that I know how many times this report has run. Can anyone help?


FWIW, here's how I got it to work...

On my report, I have a textbox with the following ControlSource:

=DMax("RunNumber","ReportRuns","[ReportName]='" & [Name] & "'")

I also have a table, ReportRuns(ReportName (text), RunDateStamp (date/Time,
general date), RunNumber (int))
PK is ReportName, RunDateStamp

Code...

Option Compare Database
Option Explicit


Private Sub Report_Open(Cancel As Integer)

Dim strInsertSQL As String
Dim intRunNumber As Integer

'grab the next run number from the table.
intRunNumber = Nz(DMax("RunNumber", "ReportRuns", "[ReportName]='" & Me.
Name & "'"), 0) + 1
' create the insert statement
strInsertSQL = "INSERT INTO ReportRuns(ReportName, RunNumber) VALUES ('"
& Me.Name & "' ," & intRunNumber & ")"
DBEngine(0)(0).Execute strInsertSQL
End Sub

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...arted/201005/1