G
Guest
I have created a function to count the number of times that a field value
changes from a value of 0 to 1. What I am having trouble with is passing the
name of the field to the function and then using argument in the code. He is
what I have so far:
table name is alarms
field name is INFEED_1
my function call is
=CountChanges([INFEED_1])
my function is:
Public Function CountChanges(strField As String) As Integer
Dim intCount As Integer
Dim intLastValue As Integer
Set rst = CurrentDb.OpenRecordset("alarms")
rst.MoveLast
rst.MoveFirst
intLastValue = 0
CountChanges = 0
Do While Not rst.EOF
If rst!strField = 1 And intLastValue = 0 Then
CountChanges = CountChanges + 1
End If
intLastValue = rst!strField
rst.MoveNext
Loop
Set rst = Nothing
End Function
If I remove the variable strField and simply enter [INFEED_1] it works fine
but I can't seem to pass and use the name of the field.
Thanks in advance for your help.
changes from a value of 0 to 1. What I am having trouble with is passing the
name of the field to the function and then using argument in the code. He is
what I have so far:
table name is alarms
field name is INFEED_1
my function call is
=CountChanges([INFEED_1])
my function is:
Public Function CountChanges(strField As String) As Integer
Dim intCount As Integer
Dim intLastValue As Integer
Set rst = CurrentDb.OpenRecordset("alarms")
rst.MoveLast
rst.MoveFirst
intLastValue = 0
CountChanges = 0
Do While Not rst.EOF
If rst!strField = 1 And intLastValue = 0 Then
CountChanges = CountChanges + 1
End If
intLastValue = rst!strField
rst.MoveNext
Loop
Set rst = Nothing
End Function
If I remove the variable strField and simply enter [INFEED_1] it works fine
but I can't seem to pass and use the name of the field.
Thanks in advance for your help.