Filter subform by nth column in combobox (1 Viewer)

MooTube

Registered User.
Local time
Yesterday, 16:34
Joined
Jul 2, 2015
Messages
31
Hello,

I am currently having trouble filtering my subform by a different column than the bound column set in properties.

the comobobox shows the ID for the last email sent, with the combobox drop down showing the name and date of email when dropped down. I have tried 2 things and neither work...

1) Calling the filter on the combo-box column itself:

Code:
Dim myDate as string

myDate = [Forms]![BenSearchForm]![BenSearchSub]![LastEmail].[Column(5)]

DateFilt = " AND" & myDate & " BETWEEN " & "Nz([forms]![BenSearchForm].[Date3],#1/1/1900#) AND Nz([forms]![BenSearchForm].[Date4],#31/12/2100#)"

I have used similar code on another form, but I can't get the myDate variable to get to value of the 6th column in the dropdown (Date Of Email). an Easier way to look at this would be:

Code:
DateFilt = " AND [Forms]![BenSearchForm]![BenSearchSub]![LastEmail].[Column(5)]" & " BETWEEN " & "Nz([forms]![BenSearchForm].[Date3],#1/1/1900#) AND Nz([forms]![BenSearchForm].[Date4],#31/12/2100#)"

2) Inside the subform, I have set up a seperate field that reads the result of the dropdown box column(5) and shows it. For example the Email with ID 22 has a date of 4/8/15, so any record with last sent email being 22 has a record that says 4/8/15. I am trying to use this value to filter between, but am unable of passing the value to my filter.

The textbox is called "Email Date" and the Control source is "=[Forms]![BenSearchForm]![BenSearchSub]![LastEmail].[Column](5)"

It shows the correct data, but does not allow me to filter by this field, when the apply filter button is pressed it asks me for the parameter value of the LastEmail Field.


Code:
DateFilt = " AND" & " [EmailDate] BETWEEN " & "Nz([forms]![BenSearchForm].[Date3],#1/1/1900#) AND Nz([forms]![BenSearchForm].[Date4],#31/12/2100#)"

I use a number of set variables for my filters, so my filter ends up looking like

Code:
 .Filter = IDFilt + EmailFilt+ DateFilt

where all but IDFilt begin with AND. I use this on a number of other forms so I am sure this is not the issue!
 

Ranman256

Well-known member
Local time
Yesterday, 19:34
Joined
Apr 9, 2015
Messages
4,337
When I need to filter on column(5) of a combo, I use an invisible field.
When the user picks an item in the combo, in the afterupdate event, I update the invisible text box with txtBox = cboBox.column(5)
THEN the query can use the txtBox in the criteria.
Queries cannot see cboBox.column(5) (or any column except the bound one)

use this method to get extra criteria from the combo.
 

MooTube

Registered User.
Local time
Yesterday, 16:34
Joined
Jul 2, 2015
Messages
31
I tried to do this, but my filter options reside on my main from, and I am trying to filter a subform in datasheet view. I added a "dummy" field that only showed the column I needed [column(n)], but I am unable to sort or filter by this date.

The combobox is on one of the fields inside the dataview subform, the values come from another table in the database.
 

MooTube

Registered User.
Local time
Yesterday, 16:34
Joined
Jul 2, 2015
Messages
31
Ok, so the answer to this was much easier than I first imagined. I used the same row source property for the drop down box that decides the filter, and the combobox inside the subform that is going to be filtered. Because of this I could filter without having to set a variable.

If anyone needs the code ask and I will post!
 

Users who are viewing this thread

Top Bottom