I have a function. It is not associated with an event. How and where do you put it? It has been a long time since I setup a form.
Function MakeFilter() As String
If Not IsNull(Me.cboconsultant) Then
strFilter = " AND [Mclname]=" & Chr(34) & Me.cboconsultant & Chr(34)
End If
If Not IsNull(Me.cbocm) Then
strFilter = strFilter & " AND [SFRep_Last]=" & Chr(34) & Me.cbocm & Chr(34)
End If
If Not strFilter = "" Then
' Omit first " AND "
strFilter = Mid(strFilter, 6)
End If
MakeFilter = strFilter
End Function
Need a refresher on Functions
-
- Administrator
- Posts: 78475
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Need a refresher on Functions
This function belongs in the code module associated with the form that contains the combo boxes cboconsultant and cbocm.
It is intended to be called in an event procedure, for example in the On Click event of a command button that opens a report:
It is intended to be called in an event procedure, for example in the On Click event of a command button that opens a report:
Code: Select all
Private Sub cmdReport_Click
Dim strWhere As String
strWhere = MakeFilter
DoCmd.OpenReport ReportName:="MyReport", View:=acViewPreview, WhereCondition:=strWhere
End Sub
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 627
- Joined: 03 Feb 2010, 15:02
Re: Need a refresher on Functions
Thanks Hans. I knew it was a dumb question but I am creating a form and trying to use code from other databases that I have created many moons ago.