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

Sequential numbering on form by date 1

Status
Not open for further replies.

Mudskipper1000

Technical User
Oct 2, 2004
4
CA
I know you've had similar, however, I need to number each new record added to a form, display in on the form throughout the month from 1st - ...
Then reset count on form to "0" for next new month and so on. Can this be done???? Thanks in advance.
 
How are ay Mudskipper1000 . . . . .

The source for the [blue]Month[/blue], will that come from a [blue]Date Field[/blue], [blue]Actual Current Date[/blue], or what?

Calvin.gif
See Ya! . . . . . .
 
Thanks guys...
Ace. The way this form is suppose to work is this....
I have a date field, Text box field (this will be for number???) and Surname field. Each record must be numbered (1,2,3 etc...)
numbering all new cases for full month, starting back at
zero next new month and so on. If this can't work then what I will need to do is continually (i think) recreate that one table every month.
 
Mudskipper1000 . . . . .

Sorry to get back so late.

In the [blue]Before Update[/blue] event of the [blue]Date Field[/blue] copy/paste the following code (you substitute proper names in [purple]purple[/purple]):
Code:
[blue]   Dim maxIdx, Criteria As String
   Dim namIdx As String, namDate As String, namTable As String
   
   If Me.NewRecord Then
      namDate = "[purple][b]DateFieldName[/b][/purple]"
      namIdx = "[purple][b]IndexFieldName[/b][/purple]"
      namTable = "[purple][b]TableName[/b][/purple]"
      Criteria = "Month([" & namDate & "]) = " & Month(Me(namDate)) & _
                 " And " & _
                 "Year([" & namDate & "]) = " & Year(Me(namDate))
      maxIdx = DMax("[" & namIdx & "]", namTable, Criteria)
      
      If IsNull(maxIdx) Then
         Me(namIdx) = 0 [green]'Start over on new month & year[/green]
      Else
         Me(namIdx) = maxIdx + 1
      End If
   End If[/blue]
After you type in the date [blue]for a new record[/blue], the index is posted.

I found it [blue]necessary to ping against month & year[/blue] to allow the month to be zeroed properly. This way, if you find you forgot to add records to a previous month & year, [blue]the code will pickup the proper index![/blue]

[blue]Cheers![/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top