Hathman
09-22-2010, 10:12 AM
Reaching out for some help here because I think I'm missing something simple but can't seem to figure it out. I want to pass a field name into a function and then use that field name within the function. How do I declare it? I tried using datatype "Field" but that throws an error when trying to call function.
I'm dumbed this down from the original to highlight the area of focus:
Public Function HasPermission(ID As Long, InField As ?) As Boolean
On Error GoTo err_catch
Dim qrystr As String
Dim qrydef As QueryDef
Dim rst As Recordset
Dim db As Database
Set db = CurrentDb()
qrystr = "SELECT table.field1, table.field2 FROM table WHERE table.id = ID"
Set qrydef = db.CreateQueryDef("", qrystr)
Set rst = qrydef.OpenRecordset(dbOpenSnapshot)
If rst.RecordCount > 0 Then
Do Until rst.EOF
If rst!InField = True Then
HasPermission = True
Exit Function
End If
rst.MoveNext
Loop
End If
End Function
---------------------------------
Thanks,
Hathman
I'm dumbed this down from the original to highlight the area of focus:
Public Function HasPermission(ID As Long, InField As ?) As Boolean
On Error GoTo err_catch
Dim qrystr As String
Dim qrydef As QueryDef
Dim rst As Recordset
Dim db As Database
Set db = CurrentDb()
qrystr = "SELECT table.field1, table.field2 FROM table WHERE table.id = ID"
Set qrydef = db.CreateQueryDef("", qrystr)
Set rst = qrydef.OpenRecordset(dbOpenSnapshot)
If rst.RecordCount > 0 Then
Do Until rst.EOF
If rst!InField = True Then
HasPermission = True
Exit Function
End If
rst.MoveNext
Loop
End If
End Function
---------------------------------
Thanks,
Hathman