Connecting Tech Pros Worldwide Forums | Help | Site Map

Why doen not this code work on filtering a form?!

Vic
Guest
 
Posts: n/a
#1: Nov 12 '05
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?

Mike Storr
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Why doen not this code work on filtering a form?!


Is the forms AllowFilters property set to Yes (true)

Mike Storr
www.veraccess.com


"Vic" <lakicsv@ntlworld.com> wrote in message
news:523e580c.0402260339.2dcd0bb1@posting.google.c om...[color=blue]
> Dear All,
>[/color]
[color=blue]
>
> What am I missing here?[/color]


fredg
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Why doen not this code work on filtering a form?!


On 26 Feb 2004 03:39:14 -0800, Vic wrote:
[color=blue]
> 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?[/color]


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.
Closed Thread