By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

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

P: n/a
Vic
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?
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Is the forms AllowFilters property set to Yes (true)

Mike Storr
www.veraccess.com
"Vic" <la*****@ntlworld.com> wrote in message
news:52**************************@posting.google.c om...
Dear All,

What am I missing here?

Nov 12 '05 #2

P: n/a
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.
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.