Thread: Access
View Single Post
  #2  
Old May 3rd, 2010, 04:07 PM posted to microsoft.public.access.gettingstarted
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Access

You'll need to store the number of times each report is opened in a table,
ReportLog say, with columns such as ReportName (text) and RunNumber (number).
Initially enter a row for each relevant report with a zero RunNumber value.
Each time the report is opened you can increment the number in the table.
This could be done in the report's Open event procedure, but that would mean
the code would execute every time the report is opened, so if you were
amending its design for instance and switching between design view and print
preview view the code would execute each time and the number would be
incremented.

Probably better would be to execute the code only when the report is
'legitimately' opened by a user, so you'll have to control how this is done
of course, but the code would be along these lines:

Const conREPORTNAME = "YourReportNameGoesHere"

Dim cmd As ADODB.Command
Dim strSQL As String

Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText

strSQL = "UPDATE ReportLog " & _
"SET RunNumber = RunNumber+1 " & _
"WHERE ReportName = """ & conREPORTNAME & """"
cmd.CommandText = strSQL
cmd.Execute

DoCmd.OpenReport conREPORTNAME

To show the RunNumber value in the report add the ReportLog table to the
report's underlying query but do not join it to any other tables. Include
the ReportName and RunNumber columns in the query and enter the name of the
report in the 'criteria' row of the ReportName column and uncheck the 'show'
check box for the same column in query design view. You can then include a
text box anywhere in the report with RunNumber as its ControlSource property.

Ken Sheridan
Stafford, England

bcraigmiles wrote:
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?


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