On 26 Feb 2004 03:39:14 -0800, Vic wrote:
Dear All,
I am getting the following error message :
"You cannot assign a value to this object" ("Me.filter =" is
highlighted)
I have two comboboxes (ByGenes and BySpecies)with lists in them on a
form. I want to be able to do filtering on a form by connecting two
criteria with a boolean expression (and). I want to get the two
criteria selected from the comboboxes then the form should be filtered
(Bygenes.value = 9 means "All" BySpecies.values = 8 means "All" in
the combobox lists)
Private Sub ByGenes_AfterUpdate()
If ByGenes.Value = 9 Or IsNull(Me.ByGenes) Then
Exit Sub
Else
Me.Filter = Me.Filter & " AND" & " GeneID = " & Me.ByGenes
Me.FilterOn = True
End If
End Sub
Private Sub BySpecies_AfterUpdate()
If BySpecies.Value = 8 Or IsNull(Me.BySpecies) Then
Exit Sub
Else
Me.Filter = Me.Filter & " AND" & " SpeciesID = " &
Me.BySpecies
Me.FilterOn = True
End If
End Sub
What am I missing here?
re: Me.Filter = Me.Filter & " AND" & " SpeciesID = " & Me.BySpecies
I can duplicate your error message ONLY if there is no filter already
in the Me.Filter. In other words the filter is blank.
However your code does works fine if, for example,
Me.Filter = "LastName] = 'Smith'".
Then adding the " and [SpeciesID] = " & Me.Byspecies
to the above filter is fine.
Nowhere in your code do you indicate Me.Filter already has an existing
string value.
Try adding an If .. Then to the procedure.
Private Sub ByGenes_AfterUpdate()
If ByGenes.Value = 9 Or IsNull(Me.ByGenes) Then
Exit Sub
Else
If IsNull(Me.Filter) Or Me.Filter = "" Then
Me.Filter = "Do an alternative filter here" '
Else
Me.Filter = Me.Filter & " AND" & " GeneID = " & Me.ByGenes
End If
Me.FilterOn = True
End If
End Sub
You can simplify your Me.Filter a bit by doing the following:
Me.Filter = Me.Filter & " AND GeneID = " & Me.ByGenes
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.