The heart of my db is a large table ([voters]) that I receive periodically from an outside source. Within the table is a series of fields that represent the voting history of each voter. Over time, new fields are added to the table representing each election as it happens, and older fields are dropped out to keep the number of fields more or less constant.
If a voter came out to the polls to vote in a given election, the corresponding field will have some variable text in it, otherwise it's null.
I have a utility function I use to add up how many times a voter actually came out to vote lately. I pass the fields of interest as a parameter array since the number of them we need to look at varies depending on where we are in the yearly election cycle. This function works just fine:
The trouble is, as the voter table gets updated with new elections, I need to periodically edit the list of fields passed to refer to the most recent elections, and how many of them to look at.
The names of the fields follow a predictable pattern, and I can easily construct strings with the names of the fields needed by looking at the current date. But I can't figure out how to use these strings to refer to fields in my table.
Can anyone help me out?
If a voter came out to the polls to vote in a given election, the corresponding field will have some variable text in it, otherwise it's null.
I have a utility function I use to add up how many times a voter actually came out to vote lately. I pass the fields of interest as a parameter array since the number of them we need to look at varies depending on where we are in the yearly election cycle. This function works just fine:
Code:
Function votes(ParamArray elections() As Variant) As Integer
Dim i As Integer
votes = 0
For i = 0 To UBound(elections())
If Not (IsNull(elections(i))) Then
votes = votes + 1
End If
Next
End Function
The names of the fields follow a predictable pattern, and I can easily construct strings with the names of the fields needed by looking at the current date. But I can't figure out how to use these strings to refer to fields in my table.
Can anyone help me out?
Last edited: