Valery
Registered User.
- Local time
- Today, 02:11
- Joined
- Jun 22, 2013
- Messages
- 363
Hi all!
This is a module that creates a query (correct me if I am saying this wrong ).
I would like to modify it to include more fields with some criteria. I have no idea where that would go - obviously I did not write this wonderful module.
These are the fields I would like to add and their criteria. All the fields are in the tblTenant table.
MailList - a Yes/No field - CRITERIA =-1
Status - a text field - CRITERIA = "M" or "F"
LabelFlag - a Yes/No Field - CRITERIA = -1
Deactivate - a text field - CRITERIA = "N"
Thank you! Please don't hesitate if you need more info.
Module:
This is a module that creates a query (correct me if I am saying this wrong ).
I would like to modify it to include more fields with some criteria. I have no idea where that would go - obviously I did not write this wonderful module.
These are the fields I would like to add and their criteria. All the fields are in the tblTenant table.
MailList - a Yes/No field - CRITERIA =-1
Status - a text field - CRITERIA = "M" or "F"
LabelFlag - a Yes/No Field - CRITERIA = -1
Deactivate - a text field - CRITERIA = "N"
Thank you! Please don't hesitate if you need more info.
Module:
Code:
Public Function GetField(UnitNo As Long, TenantOrd As Long, FieldName As String, Optional QueryName As String = "qry_F_TenantList") As Variant
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim TenantCount As Long
TenantCount = DCount("*", QueryName, "UnitNum = " & UnitNo)
If TenantOrd > TenantCount Or TenantOrd < 1 Or TenantCount = 0 Then
GetField = Null
Exit Function
End If
strSQL = "SELECT " & FieldName & " " & _
"FROM [" & QueryName & "] " & _
" WHERE UnitNum = " & UnitNo & " " & _
"ORDER BY Status ;"
Set qdf = CurrentDb.CreateQueryDef("", strSQL)
'qdf.Parameters("[forms]![frmLabels]![Gender]") = [Forms]![frmLabels]![Gender]
Set rs = qdf.OpenRecordset
rs.Move TenantOrd - 1
GetField = rs.Fields(FieldName)
qdf.Close
rs.Close
End Function