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

How to add a counter to an access form footer 2

Status
Not open for further replies.

vdubill

MIS
Dec 5, 2006
11
0
0
US
I am trying to add a counter to a form footer so that I can limit the number of additions to a local table. Any idea.

vdub
 
You can use the recordset of the subform to get a count (recordcount).
 
if you need a record counter you could add a unbound text box and in the control source use the DCount function

I will try my best to help others so will others do!!!!!
IGPCS
Brooklyn, NY
 
I am trying the Dcount function in an unbound text box and it is not working out too well. Here is what I have for the control source of the text box: =DCount([q_GET_STUDENT_INFO]![STUDENT_GRADING.ID#],[q_GET_STUDENT_INFO])

yet it only shows #NAME?

any ideas.
 
And this ?
=DCount("[STUDENT_GRADING.ID#]","q_GET_STUDENT_INFO")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
If your intention is to limit the number of records, checking the RecordCount in a suitable event should suit.

Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
MaxRecs = 6
If Me.Recordset.RecordCount >= MaxRecs Then
    MsgBox "Set complete"
    Me.Undo
    Cancel = True
    Me.Recordset.MoveLast
End If
End Sub
 
thanks phv that worked, but I dont think it is what I wanted to do. I had an idea with the counter, but it is not working.

remou,
I tried to add ur code and I am not getting a message box. the name of my textbox is cntrecord and the dcount is at 7. So shouldnt the following event shoot me a msg when I try to add another record?

Private Sub cntrecord_BeforeUpdate(Cancel As Integer)

MaxRecs = 6
If Me.Recordset.RecordCount >= MaxRecs Then
MsgBox "Set complete"
Me.Undo
Cancel = True
Me.Recordset.MoveLast
End If

End Sub
 
What happens when you step through the code?
 
Have you tried the BeforeInsert event instead ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Remou,

Actually your last code did work. I was mistaken and put it in the vb code for the text box instead of the form. It works for me now. thanks

also, can i use this same method to limit the amount of data shown in a report?

thanks a bunch everybody.
 
The usual way of limiting data in a report is to use a query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top