473,418 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Filter a Form by Date Field in Subform

I'm trying to filter the records on the mainform (MailingList) of my
database using a field contained in a subform (Donations). I was
basing my code off Allen Browne's Access Tips page (here:
http://allenbrowne.com/ser-28.html) since it has worked so well in the
past. However, now I'm trying to filter by date instead of by a
string or a number, and I'm getting nowhere. My goal is to have users
type a date into the unbound combo box and have that search a
particular field (RequestDue, also a date) in Donations and return all
records that match.

I have an unbound combo box on the mainform where users can type in
the date they want to search for. Here are the (hopefully) relevant
properties:
Name: cboRequestDueSearch
Control Source: <blank>
Format: Short Date
Row Source Type: Table/Query
Row Source: Donations
Column Count: 30
Bound Column: 25

I have all of the column widths set to 0", save for the column I
actually care about.

Here is the code I currently have running as the AfterUpdate Event:
Private Sub cboRequestDueSearch_AfterUpdate()
Dim strSQL As String
If IsNull(Me.cboRequestDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingList"
Else
strSQL = "SELECT DISTINCTROW MailingList.* FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.MailingListID = Donations.MailingListID " & _
"WHERE Donations.RequestDue = " & Me.cboRequestDueSearch & ";"
Me.RecordSource = strSQL
End If
End Sub

I could type in all the variations of this I have tried, but it would
be very long. The combo box is looking in the right field of the
Donations table and I am no longer getting errors when I try to search
for a date. However, when I do search, Access says 'calculating...'
for a while, but then returns all records. No records are filtered
out.

Can anyone help me out? Thanks in advance for the advice!

Katherine

Jul 12 '07 #1
7 6690
When you put the date into the string, you need to add # around it. If your
date format is non-US, you need to tell Access to use the US format.

So, the code will contain:
"WHERE Donations.RequestDue = " & _
Format(Me.cboRequestDueSearch, "\#mm\/dd\/yyyy\#" & ";"

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Katherine" <Oa****************************@gmail.comwrote in message
news:11*********************@22g2000hsm.googlegrou ps.com...
I'm trying to filter the records on the mainform (MailingList) of my
database using a field contained in a subform (Donations). I was
basing my code off Allen Browne's Access Tips page (here:
http://allenbrowne.com/ser-28.html) since it has worked so well in the
past. However, now I'm trying to filter by date instead of by a
string or a number, and I'm getting nowhere. My goal is to have users
type a date into the unbound combo box and have that search a
particular field (RequestDue, also a date) in Donations and return all
records that match.

I have an unbound combo box on the mainform where users can type in
the date they want to search for. Here are the (hopefully) relevant
properties:
Name: cboRequestDueSearch
Control Source: <blank>
Format: Short Date
Row Source Type: Table/Query
Row Source: Donations
Column Count: 30
Bound Column: 25

I have all of the column widths set to 0", save for the column I
actually care about.

Here is the code I currently have running as the AfterUpdate Event:
Private Sub cboRequestDueSearch_AfterUpdate()
Dim strSQL As String
If IsNull(Me.cboRequestDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingList"
Else
strSQL = "SELECT DISTINCTROW MailingList.* FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.MailingListID = Donations.MailingListID " & _
"WHERE Donations.RequestDue = " & Me.cboRequestDueSearch & ";"
Me.RecordSource = strSQL
End If
End Sub

I could type in all the variations of this I have tried, but it would
be very long. The combo box is looking in the right field of the
Donations table and I am no longer getting errors when I try to search
for a date. However, when I do search, Access says 'calculating...'
for a while, but then returns all records. No records are filtered
out.

Can anyone help me out? Thanks in advance for the advice!

Katherine
Jul 13 '07 #2
On Jul 13, 5:23 am, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
When you put the date into the string, you need to add # around it. If your
date format is non-US, you need to tell Access to use the US format.

So, the code will contain:
"WHERE Donations.RequestDue = " & _
Format(Me.cboRequestDueSearch, "\#mm\/dd\/yyyy\#" & ";"

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Katherine" <OatBoatBaBoatBoatMcBoatNut....@gmail.comwrote in message

news:11*********************@22g2000hsm.googlegrou ps.com...
I'm trying to filter the records on the mainform (MailingList) of my
database using a field contained in a subform (Donations). I was
basing my code off Allen Browne's Access Tips page (here:
http://allenbrowne.com/ser-28.html) since it has worked so well in the
past. However, now I'm trying to filter by date instead of by a
string or a number, and I'm getting nowhere. My goal is to have users
type a date into the unbound combo box and have that search a
particular field (RequestDue, also a date) in Donations and return all
records that match.
I have an unbound combo box on the mainform where users can type in
the date they want to search for. Here are the (hopefully) relevant
properties:
Name: cboRequestDueSearch
Control Source: <blank>
Format: Short Date
Row Source Type: Table/Query
Row Source: Donations
Column Count: 30
Bound Column: 25
I have all of the column widths set to 0", save for the column I
actually care about.
Here is the code I currently have running as the AfterUpdate Event:
Private Sub cboRequestDueSearch_AfterUpdate()
Dim strSQL As String
If IsNull(Me.cboRequestDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingList"
Else
strSQL = "SELECT DISTINCTROW MailingList.* FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.MailingListID = Donations.MailingListID " & _
"WHERE Donations.RequestDue = " & Me.cboRequestDueSearch & ";"
Me.RecordSource = strSQL
End If
End Sub
I could type in all the variations of this I have tried, but it would
be very long. The combo box is looking in the right field of the
Donations table and I am no longer getting errors when I try to search
for a date. However, when I do search, Access says 'calculating...'
for a while, but then returns all records. No records are filtered
out.
Can anyone help me out? Thanks in advance for the advice!
Katherine
Thanks for the reply. I tried out the code you gave, but it gave me
an error about a missing ')', so I altered the code as follows to end
the parathetical statement:

"WHERE Donations.RequestDue = " & _
Format(Me.cboRequestDueSearch, "\#mm\/dd\/yyyy\#") & ";"

The result didn't change. The records still aren't filtered in any
way after entering a date in the combo box.

Do you have any other suggestions?

Katherine

Jul 13 '07 #3
Hi,
try adding a Me.Requery after the 'Me.RecordSource = strSQL' and
before the 'End If' statement
Me.RecordSource = strSQL
End If

bobh.

On Jul 13, 11:45 am, Katherine
<OatBoatBaBoatBoatMcBoatNut....@gmail.comwrote:
On Jul 13, 5:23 am, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:


When you put the date into the string, you need to add # around it. If your
date format is non-US, you need to tell Access to use the US format.
So, the code will contain:
"WHERE Donations.RequestDue = " & _
Format(Me.cboRequestDueSearch, "\#mm\/dd\/yyyy\#" & ";"
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Katherine" <OatBoatBaBoatBoatMcBoatNut....@gmail.comwrote in message
news:11*********************@22g2000hsm.googlegrou ps.com...
I'm trying to filter the records on the mainform (MailingList) of my
database using a field contained in a subform (Donations). I was
basing my code off Allen Browne's Access Tips page (here:
>http://allenbrowne.com/ser-28.html) since it has worked so well in the
past. However, now I'm trying to filter by date instead of by a
string or a number, and I'm getting nowhere. My goal is to have users
type a date into the unbound combo box and have that search a
particular field (RequestDue, also a date) in Donations and return all
records that match.
I have an unbound combo box on the mainform where users can type in
the date they want to search for. Here are the (hopefully) relevant
properties:
Name: cboRequestDueSearch
Control Source: <blank>
Format: Short Date
Row Source Type: Table/Query
Row Source: Donations
Column Count: 30
Bound Column: 25
I have all of the column widths set to 0", save for the column I
actually care about.
Here is the code I currently have running as the AfterUpdate Event:
Private Sub cboRequestDueSearch_AfterUpdate()
Dim strSQL As String
If IsNull(Me.cboRequestDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingList"
Else
strSQL = "SELECT DISTINCTROW MailingList.* FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.MailingListID = Donations.MailingListID " & _
"WHERE Donations.RequestDue = " & Me.cboRequestDueSearch & ";"
Me.RecordSource = strSQL
End If
End Sub
I could type in all the variations of this I have tried, but it would
be very long. The combo box is looking in the right field of the
Donations table and I am no longer getting errors when I try to search
for a date. However, when I do search, Access says 'calculating...'
for a while, but then returns all records. No records are filtered
out.
Can anyone help me out? Thanks in advance for the advice!
Katherine

Thanks for the reply. I tried out the code you gave, but it gave me
an error about a missing ')', so I altered the code as follows to end
the parathetical statement:

"WHERE Donations.RequestDue = " & _
Format(Me.cboRequestDueSearch, "\#mm\/dd\/yyyy\#") & ";"

The result didn't change. The records still aren't filtered in any
way after entering a date in the combo box.

Do you have any other suggestions?

Katherine- Hide quoted text -

- Show quoted text -

Jul 13 '07 #4
On Jul 13, 1:26 pm, bobh <vulca...@isp.comwrote:
Hi,
try adding a Me.Requery after the 'Me.RecordSource = strSQL' and
before the 'End If' statement
Me.RecordSource = strSQL
End If

bobh.

On Jul 13, 11:45 am, Katherine

<OatBoatBaBoatBoatMcBoatNut....@gmail.comwrote:
On Jul 13, 5:23 am, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
When you put the date into the string, you need to add # around it. If your
date format is non-US, you need to tell Access to use the US format.
So, the code will contain:
"WHERE Donations.RequestDue = " & _
Format(Me.cboRequestDueSearch, "\#mm\/dd\/yyyy\#" & ";"
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Katherine" <OatBoatBaBoatBoatMcBoatNut....@gmail.comwrote in message
>news:11*********************@22g2000hsm.googlegro ups.com...
I'm trying to filter the records on the mainform (MailingList) of my
database using a field contained in a subform (Donations). I was
basing my code off Allen Browne's Access Tips page (here:
http://allenbrowne.com/ser-28.html) since it has worked so well in the
past. However, now I'm trying to filter by date instead of by a
string or a number, and I'm getting nowhere. My goal is to have users
type a date into the unbound combo box and have that search a
particular field (RequestDue, also a date) in Donations and return all
records that match.
I have an unbound combo box on the mainform where users can type in
the date they want to search for. Here are the (hopefully) relevant
properties:
Name: cboRequestDueSearch
Control Source: <blank>
Format: Short Date
Row Source Type: Table/Query
Row Source: Donations
Column Count: 30
Bound Column: 25
I have all of the column widths set to 0", save for the column I
actually care about.
Here is the code I currently have running as the AfterUpdate Event:
Private Sub cboRequestDueSearch_AfterUpdate()
Dim strSQL As String
If IsNull(Me.cboRequestDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingList"
Else
strSQL = "SELECT DISTINCTROW MailingList.* FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.MailingListID = Donations.MailingListID " & _
"WHERE Donations.RequestDue = " & Me.cboRequestDueSearch & ";"
Me.RecordSource = strSQL
End If
End Sub
I could type in all the variations of this I have tried, but it would
be very long. The combo box is looking in the right field of the
Donations table and I am no longer getting errors when I try to search
for a date. However, when I do search, Access says 'calculating...'
for a while, but then returns all records. No records are filtered
out.
Can anyone help me out? Thanks in advance for the advice!
Katherine
Thanks for the reply. I tried out the code you gave, but it gave me
an error about a missing ')', so I altered the code as follows to end
the parathetical statement:
"WHERE Donations.RequestDue = " & _
Format(Me.cboRequestDueSearch, "\#mm\/dd\/yyyy\#") & ";"
The result didn't change. The records still aren't filtered in any
way after entering a date in the combo box.
Do you have any other suggestions?
Katherine- Hide quoted text -
- Show quoted text -
Thanks for the suggestion. I did try it, but still no change. The
records are not being filtered at all.

Katherine

Jul 13 '07 #5
On Jul 13, 4:05 pm, Katherine
<OatBoatBaBoatBoatMcBoatNut....@gmail.comwrote:
Thanks for the suggestion. I did try it, but still no change. The
records are not being filtered at all.

Katherine
I just tried an example with

"WHERE Donations.RequestDue = #" & Me.cboRequestDueSearch & "#;"

It worked. That might make yours work.

If not, try a separate query using the following SQL:

SELECT Donations.RequestDue, Forms!MailingList.cboRequestDueSearch AS
FormDate FROM MailingList INNER JOIN Donations ON
MailingList.MailingListID = Donations.MailingListID;

Note: Do this with the MailingList form open and with a value selected
for cboRequestDueSearch. I used:

SELECT DISTINCT RequestDue FROM Donations WHERE RequestDue IS NOT
NULL;

as the RowSource of the combobox on the MailingList form.

Compare the date values.

Having time information in the date field would not cause a lack of
filtering. A Null value equates to everything, but a spelling mistake
should cause a prompt to come up.

James A. Fortune
CD********@FortuneJames.com

Jul 13 '07 #6
On Jul 13, 5:15 pm, CDMAPos...@FortuneJames.com wrote:
On Jul 13, 4:05 pm, Katherine

<OatBoatBaBoatBoatMcBoatNut....@gmail.comwrote:
Thanks for the suggestion. I did try it, but still no change. The
records are not being filtered at all.
Katherine

I just tried an example with

"WHERE Donations.RequestDue = #" & Me.cboRequestDueSearch & "#;"

It worked. That might make yours work.

If not, try a separate query using the following SQL:

SELECT Donations.RequestDue, Forms!MailingList.cboRequestDueSearch AS
FormDate FROM MailingList INNER JOIN Donations ON
MailingList.MailingListID = Donations.MailingListID;

Note: Do this with the MailingList form open and with a value selected
for cboRequestDueSearch. I used:

SELECT DISTINCT RequestDue FROM Donations WHERE RequestDue IS NOT
NULL;

as the RowSource of the combobox on the MailingList form.

Compare the date values.

Having time information in the date field would not cause a lack of
filtering. A Null value equates to everything, but a spelling mistake
should cause a prompt to come up.

James A. Fortune
CDMAPos...@FortuneJames.com
James,

I tried the first thing you suggested (with the # signs), and the
results didn't change. Still no filtering.

The second suggestion you had may be leading me down the right path,
but I'm not sure what the next step is. I altered the RowSource of
the combo box as you said and then ran the query you suggested. The
date results for RequestDue look like they are formatted wrong in the
results - they all have extra spaces in them. Some examples are 12/1 /
07 and 9 /7 /07 and 1 /10/10.

This may help explain why the filtering is not working as I'd like,
but, if that is the case, I'm not sure what steps to take to correct
the problem. Any thoughts?

Katherine

Jul 16 '07 #7
On Jul 16, 12:43 pm, Katherine
<OatBoatBaBoatBoatMcBoatNut....@gmail.comwrote:
James,

I tried the first thing you suggested (with the # signs), and the
results didn't change. Still no filtering.

The second suggestion you had may be leading me down the right path,
but I'm not sure what the next step is. I altered the RowSource of
the combo box as you said and then ran the query you suggested. The
date results for RequestDue look like they are formatted wrong in the
results - they all have extra spaces in them. Some examples are 12/1 /
07 and 9 /7 /07 and 1 /10/10.

This may help explain why the filtering is not working as I'd like,
but, if that is the case, I'm not sure what steps to take to correct
the problem. Any thoughts?

Katherine
Katherine,

You've certainly thrown some curveballs.

I think the example I tried worked with RequestDue formatted as either
Date/Time or as Text, but without any spaces. If the spaces are
stored in a text field you can open the table, click on the field
header and use Edit...Replace... with 'Match Whole Field' unchecked to
replace spaces with nothing or, alternatively for later versions of
Access, run an update query using the Replace function. Some ways
that the spaces can get there in the first place include:

1) It was stored in the mainframe that way.

2) The number was written into a string variable initialized as two
spaces causing a single digit to left-justify before being written out
to a file.

If you are unable to change the formatting or edit the original
values, try:

Private Sub cboRequestDueSearch_AfterUpdate()
Dim strSQL As String

If IsNull(Me.cboRequestDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingList"
Else
strSQL = "SELECT Donations.RequestDue FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.MailingListID = Donations.MailingListID " & _
"WHERE Donations.RequestDue = " & Chr(34) & Me.cboRequestDueSearch
& Chr(34) & ";"
Me.RecordSource = strSQL
End If
End Sub

That will cause a text match of your "spaced-out" dates from the table
with the "spaced-out" list in your combobox. Be sure to take out the
'Short Date' format from cboRequestDueSearch before trying it that
way. If you are able to remove all the spaces from RequestDue,
consider converting the text field into a Date/Time data type. If
RequestDue is truly a Date/Time field already then you need to find
out where the strange formatting is coming from. Maybe your 'Short
Date' format got messed up somehow.

James A. Fortune
CD********@FortuneJames.com

Jul 17 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
2
by: Brian Newman | last post by:
I've got what is actually a triple-layer nested form. That part works fine. I've got the first subform related by the right key field to the main form, then I've got the second subform related to...
7
by: damjanu | last post by:
Hi All; I need little help. I have a datasheet form. I allow user to do 'filter by selection'. My form contains a column with values. As user changes selections, I want to calculate totals....
0
by: Colin | last post by:
In access 2000 I need to filter records in a Subform by pushing a button on a command button located on the Main form. The Main form is blank. Its only purpose is to contain the subform which is...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
2
by: cefrancke | last post by:
I have a form (no underlying record set) that has two separate sub-forms on it. Each sub-form has data from two different tables. Above each sub-form there is one unbound combo box with a SQL...
2
by: Lenin Torres | last post by:
Hi everybody I have an Union Query that works fine. I used this query as the RecordSource for a Form. That Form is used as a subform in another form. Everything works fine, except for the "Filter...
0
by: Stinky Pete | last post by:
Hi, The db I'm trying to update has a report form from which all other statistical forms and reports are selected/printed by dept, type, cost, number etc. The report form uses a date filter to...
0
by: diogenes | last post by:
"Rick Brandt" <rickbrandt2@hotmail.comwrote in news:bPnKj.456$%41.325 @nlpi064.nbdc.sbc.com: I used this approach, and it works a treat! ID In(SELECT Order_ID FROM orderitems WHERE NAME =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.