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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incrementing a user-entered # on a report

Status
Not open for further replies.

Gooter

Technical User
Apr 5, 2002
20
US
First of all, I am a complete novice with Acess. Here is what I want to try to do.

I want to create a report that takes a user-entered number from a form and then auto-increments that number by one for each record generated on the report.

For example...

1. The user enters "25" into a box on the form.
2. Let's say the report pulls 5 records. I want the first record to start with 25, the second 26, third 27, ... , and the fifth 29.

I don't need to store these numbers in a table. I only need it for output purposes. I am assuming the report will have a text box dedicated to the numbers I want to output. I know how to map the text box to the number the user enters on the form

ControlSource in text box: =[Forms]![NAMEofFORM]![FIELDonFORM]

My problem is I can not figure out how to increment that number by one for each record generated on the report.

If you need further info, please let me know. I hope I explained everything clearly.

Thank you in advance for your help,
MG

 
Create a new module and copy in this code -

Global glngNumber As Long

Public Function GetIncrement(varDummy As Variant) As Long

GetIncrement = glngNumber

glngNumber = glngNumber + 1

End Function

On your form, enter this code in the After_Update Event of the TextBox that is to hold the initial value -

Private Sub YourTextBox_AfterUpdate()

glngNumber = Me.YourTextBox

End Sub

In the underlying query of your report, call this function with one of the other fields in your query as an argument (this forces the query to call the function for every row.) i.e. -

SomeAlias: GetIncrement([AnyOfYourQueryFields])

Place a TextBox on your form that has the above field as it's control source.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top