Run-time error 2448; You can't assign a value to this object

Neil_Pattison

Registered User.
Local time
Today, 17:35
Joined
Aug 24, 2005
Messages
73
Hi all,

I have a form that runs from a query which combines data from 2 tables. I am trying to set up a filter on the form using a number of combo boxes and text boxes and a command button to fire it but I keep getting the above error (on the .Filter = strFilter line) and I can't see what the problem is with my code.

Private Sub cmdApplyFilter_Click()

Dim strSSType As String
Dim strArea As String
Dim strDepot As String
Dim strStatus As String
Dim strRisk As String
Dim strZone As String
Dim strContractor As String
Dim strFilter As String

If IsNull(Me.cboSSType.Value) Then
strSSType = "'Like '*'"
Else
strSSType = "='" & Me.cboSSType.Value & "'"
End If

If IsNull(Me.cboArea.Value) Then
strArea = "'Like '*'"
Else
strArea = "='" & Me.cboArea.Value & "'"
End If

If IsNull(Me.cboDepot.Value) Then
strDepot = "'Like '*'"
Else
strDepot = "='" & Me.cboDepot.Value & "'"
End If

If IsNull(Me.cboStatus.Value) Then
strStatus = "'Like '*'"
Else
strStatus = "='" & Me.cboStatus.Value & "'"
End If

If IsNull(Me.cboRisk.Value) Then
strRisk = "'Like '*'"
Else
strRisk = "='" & Me.cboRisk.Value & "'"
End If

If IsNull(Me.cboZone.Value) Then
strZone = "'Like '*'"
Else
strZone = "='" & Me.cboZone.Value & "'"
End If

If IsNull(Me.cboContractor.Value) Then
strContractor = "'Like '*'"
Else
strContractor = "='" & Me.cboContractor.Value & "'"
End If

strFilter = "[subSubstationType] " & strSSType & "AND [subArea] " & strArea & "AND [subDepot] " & strDepot & "AND [subStatus] " & strStatus & "AND [subRiskLevel] " & strRisk & "AND [subZone] " & strZone & "AND [subContractor] " & strContractor

With Forms![frmSubInfo]
.Filter = strFilter
.FilterOn = True
End With

End Sub


Any help on this would be greatly appreciated.
 
Forms![frmSubInfo].form.Filter = strFilter
Forms![frmSubInfo].form.FilterOn = True

???
 
thanks for your reply Ken. I've tried that but still come up with the same run-time error
 
Are you trying to set the filter on a subform?
 
The form does have 2 subforms on it but the filter is only in regard to the parent form
 
Oh, my bad with the form name having 'sub' in it I thought maybe you trying to filter a subform.

So the following code will not work either?

Forms![frmSubInfo].Filter = strFilter
Forms![frmSubInfo].FilterOn = True

What about:

me.Filter = strFilter
me.FilterOn = True

(If the button is on the same form that you are trying to filter...)
 
Yeah I can see why that would be confusing. Using

me.filter = strFilter
me.FilterOn = True

still brings up the same run time error though
 
The problem is your assignment of the variables:


It ISN'T this:
Code:
If IsNull(Me.cboZone.Value) Then
   strZone = "'Like '*'"
Else
   strZone = "='" & Me.cboZone.Value & "'"
End If

It should be this:
Code:
If IsNull(Me.cboZone.Value) Then
   strZone = "[color=red][Zone][/color] Like '*'"
Else
   strZone = "[color=red][Zone][/color]='" & Me.cboZone.Value & "'"
End If

So, you need to fix ALL of your items to include the field that it is referring to.
 
Good catch Bob -

Did that fix it?

fyi: If not you may want to try rolling in one corrected filter item at a time until you get them all working...
 
Actually I see that you were trying to do what I said at the end and in that case you might just take the extra ' away from the LIKE statements. You have "'Like '*'" in the code but there is one unmatched ' in there (so "Like '*'" instead).
 

Users who are viewing this thread

Back
Top Bottom