Detail Numbering

K

Kurt

I would like to number the detail records in my report. I would supply a
starting seed value via an input box. I know this sounds strange, it is for
a check numbering report.

Thanks for any help.

Kurt
 
O

Ofer Cohen

One option
1. Create a text box in the report detail to display the counter

2. In the report decleation declare a variable

Option Compare Database
Dim StartNumber As Long

3. In the Report Header OnPrint event write the code
' To get the user input
StartNumber = InputBox("please select a number")
Me.FieldName = Null

4. In the Detail section OnPrint event where the text box is located write
the code

If IsNull(Me.FieldName) Then
Me.FieldName = StartNumber
Else
Me.FieldName = Me.FieldName + 1
End If


***************
Note: don't forget to change the field name in the code
 
D

Duane Hookom

You should be able to do this without code. Add a new calculated column to
your report's record source:
StartNumber: [Enter Start Number]
Then create a text box in the detail section:
Name: txtRunSum
Control Source: -1
Running Sum: Over All
Visible: No
Then create another text box in the detail section:
Control Source: =[StartNumber]+[txtRunSum]-1
 
O

Ofer Cohen

Hi Duane,
I thought of this option, but for some reason I thought that if the report
is printed after it's been viewed, it will start the counter from where the
view stoped.
I tried it and it start from the beginning, so your method is shorter.

Just one point
The control source of txtRunSum should be: =1 and not -1

Which I assume is a type error
 
Z

Zedbiker

I am using this method of adding order numbers to my reports. I must admit I
found your explanation easier to understand. It works really well.
However if the user presses the "Cancel" button at the input box there is an
error due to it expecting a number rather than text. According to info on
Input Box "Cancel" creates a blank string which obviously throws up an error
as it expects a Long number.
Is there an easy way of getting around this problem.
Many thanks for any help.
 
O

Ofer Cohen

It's depend on what value you want to assign to the counter, you can check it
for numeric value, if it's not you can assign 1 after giving a message

Dim Reply As variant

Reply = InputBox("please select a number")
If Not IsNumeric(Reply) Then
MsgBox "No proper data was entred, the counter will start with 1"
StartNumber = 1
Else
StartNumber = Reply
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top