G'day Ppl
A long time ago, someone was kind enough to provide me with a code to
update
a counter control when the form opened.
e.g each time the form opened the counter control would increase by 1.
Something like
Me.Counter = Me.Counter + 1
not sure where it goes, tried BeforeUpdate() and OnOpen(), neither worked.
Is Counter a field in your form's recordsource? If not, then the value of
Counter would (probably) be 0 everytime the
form opens.
I'd suspect you'd be better off using either (a) a gobal variable or (b) a
stored value to do this. To use a global
variable, add this to a Standard Module:
[General Declarations section]
Public gintFormCount as Integer
Now when your form Opens:
Sub Form_Open(Cancel As Integer)
mingFormCount = mintFormCount +1
End Sub
This is the easiest way to do it, but in general I like to avoid global
variables, since they can lose their value if,
for example, an unhandled error occurs.
To do a table-based value, add a table (tSettings) with two fields
(tSettingName and tSettingValue, both Text fields).
Add a record to this table:
tSettingName="FormCount"
tSettingValue = "0"
Now add a function to a Standard Module:
Function IncrementFormCount() As Boolean
Dim lngCount As Long
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("SELECT * FROM tSettings WHERE
sSettingName='FormCount'")
If Not (rst.EOF And rst.BOF) Then
rst.Edit
rst("sSettingvalue") = CStr(Val(rst("sSettingValue")) + 1)
rst.Update
End If
Set rst = Nothing
End Function
Now to increment the counter, call the function when the form opens:
Sub Form_Open(Cancel As Integer)
IncrementFormCount
End Sub
Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com