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

Record counter for a form in Datasheet View

Status
Not open for further replies.

inuman

Programmer
Feb 23, 2006
20
RO
Hello!

I have a form and a subform in Datasheet View which displays a list of records.
I want to put a field in the subform which counts the position of the records, which should start from 1, every time the main form changes from one record to another.
Subform should lokk like this:
NR Name
1 John
2 Doe

Thank you!
 
You will need to base the subform on a query of some description, for example:

Displaying Record Number on Access Continuous Form
thread702-784137
Number Records in Query
thread701-1131907
How do I add a sequential count on my query?
thread701-754405

However, the subsequent recordset will not be updateable.

 
Thanks for your reply, but I want it to be updatable.
Is there a way to do this?
 
Not that I know of. Is it essential that you use a datasheet? A continuous form can be made to look very like a datasheet and it will allow you to have numbers and an updateable recordset.
 
I didn't think about this variant :p
I think this will do the trick.
I'll write again to tell you if it works.

Thanks a lot!
 
I tried with Continous form but it gives the same error:
First time I open the form it shows 1,2,3,4 (correct counter), but when I change to another record in the main form, the subform shows 1,1,2,3 (wrong counter). I don't know why the counter works like this...
 
I use a module:

Public gvarCountRec As Integer

Function Counter() As Integer
gvarCountRec = gvarCountRec + 1
Counter = gvarCountRec
End Function

And an unbound textbox on the subform with value: =Counter()
In the main form's On Current event: gvarCountRec=0
 
When you say a module, do you mean the module belonging to a form? I ask, just to be sure. :)
 
I was afraid you would say that. I have tried this counter and it is working for me. In fact, it even works with datasheet view. I will fiddle a bit, to see if I can break it.
 
How does it work for you? Have you put the Function in the subform's module?
 
No, I put in everything exactly as you described: function and global variable in a global module, gvarCountRec = 0 in the current event of the main form. Are you sorting or such like?
 
Nope, just a subform which change it's content linked to the main's form field
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top