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

COUNT OR COUNTER

Status
Not open for further replies.

hrg

Programmer
Jan 8, 2009
46
US
Hello

I have a problem where i am trying to count the number of records i enter into a form. I have a count txtbox which is locked and only displays a number of records entered. The code below only seems to display one every time i exit the First name field is there something wrong with my code (below)

Private Sub txtName_Exit(Cancel As Integer)
Dim intCounter As Integer


intCounter = 0

If intCounter < 50 Then
Counter = intCounter + 1
TxtCount = intCounter

Else

If intCounter = 50 Then
MsgBox (&quot;G&quot;)
End If

End If
End Sub

So basically on exiting the first name field add one to the counter(incounter and display in txt box) then when reaching 50 display a message (&quot;full&quot;) and then reset counter to 0. This is what i would like the program to do but for some reason it is not please can anyone help.

Thank you for your time.
 
In the code it is wrote wrong

Counter = intCounter +1

I have added the int but it still does not work

sorry about the typo

Thanks HRG
 
incounter always starts at 0. Every time you exit the field you are saying

textbox = 0+1

Nick
 
try,

If TxtCount < 50 Then
TxtCount = TxtCount + 1
Else
MsgBox (&quot;G&quot;)
TxtCount = 1
End If

Nick
 
If you declare intCounter within the private sub, you erase its value. You should then declare it outside, and as a public variable, obviously.

Also, somewhere you should set its initial value to 0, when you open the form for example.

The best solution I think would be the one given by nickjar2.

Rgds,

AmaHerrn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top