graviz
Registered User.
- Local time
- Today, 16:26
- Joined
- Aug 4, 2009
- Messages
- 167
I use the code listed below to create a custom function. I'm able to look at a field "service_code_string" (looks like "D0|D1|D2|D3|;=|KT|T:|2R|T0|T0|NG|A9|LK|U+|U$") and am able to test if a set of codes in in each line in the table. I'd like to try and code better and store them in a table instead of hard coding. When searching for this I tried to learn about recordsets and use that to accomplish what I'm trying to do, however I'm unable to make anything work. Any suggestions on how to do this (I named the table containing the codes "Code_Table")?
Here was my attempt at doing this:
Code:
Function DishNetActivityCode(service_code_string As String) As Integer
Dim CodeArray, i As Integer
CodeArray = Array("60", "64", "74", "8.", "~R", "R=")
For i = 0 To UBound(CodeArray)
If InStr(service_code_string, CodeArray(i)) Then
DishNetActivityCode = 1
Exit Function
End If
Next
DishNetActivityCode = 0
End Function
Here was my attempt at doing this:
Code:
Function SHS_Test(service_code_string As String) As Integer
Dim i As Integer, rs As DAO.Recordset, db As DAO.Database
Set rs = db.OpenRecordset("Code_Table", dbOpenDynaset)
For i = 0 To UBound(rs)
If InStr(service_code_string, rs(i)) Then
SHS_Test = 1
Exit Function
End If
Next
SHS_Test = 0
End Function