alsoascientist
Registered User.
- Local time
- Today, 23:21
- Joined
- Mar 26, 2012
- Messages
- 39
I have a VBA code that filters a subform dependent on the value of the current control. This has been working fine until I "tidied up" my VBA (I don't think I deleted anything, just moved things about in the same modules).
The filter should show all records that match the criteria from a query, but only one record is being returned (this used to work perfectly).
The code I have is
Me.PivotQuerySubform.Form.RecordSource = "SELECT * FROM [AllQuery] " & BuildFilter
Me.PivotQuerySubform.Requery
(Attached to the after update function of each control)
'-------------------------------------------------
'This will build the filter to call from the query
'-------------------------------------------------
Private Function BuildFilter() As Variant
Dim varWhere As Variant
select1 = Forms![FrmAdd]![CurrentControl].Value
select2 = Forms![FrmAdd]![CurrentValue].Value
varWhere = Null ' Main filter
' Check for Search 1
If select1 > "" Then
varWhere = varWhere & "[" & select1 & "] ='" & select2 & "'"
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
End If
BuildFilter = varWhere
End Function
I really can't see what I have done - I have a very similar one on a seperate form that I use as a search, and that one works fine (I have tried comparing them but I can't see what is different apart from what actually should be different)
The filter should show all records that match the criteria from a query, but only one record is being returned (this used to work perfectly).
The code I have is
Me.PivotQuerySubform.Form.RecordSource = "SELECT * FROM [AllQuery] " & BuildFilter
Me.PivotQuerySubform.Requery
(Attached to the after update function of each control)
'-------------------------------------------------
'This will build the filter to call from the query
'-------------------------------------------------
Private Function BuildFilter() As Variant
Dim varWhere As Variant
select1 = Forms![FrmAdd]![CurrentControl].Value
select2 = Forms![FrmAdd]![CurrentValue].Value
varWhere = Null ' Main filter
' Check for Search 1
If select1 > "" Then
varWhere = varWhere & "[" & select1 & "] ='" & select2 & "'"
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
End If
BuildFilter = varWhere
End Function
I really can't see what I have done - I have a very similar one on a seperate form that I use as a search, and that one works fine (I have tried comparing them but I can't see what is different apart from what actually should be different)