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: cboRequestDueSe arch
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 cboRequestDueSe arch_AfterUpdat e()
Dim strSQL As String
If IsNull(Me.cboRe questDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingLis t"
Else
strSQL = "SELECT DISTINCTROW MailingList.* FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.Ma ilingListID = Donations.Maili ngListID " & _
"WHERE Donations.Reque stDue = " & Me.cboRequestDu eSearch & ";"
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 7 6722
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.Reque stDue = " & _
Format(Me.cboRe questDueSearch, "\#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.comwrot e in message
news:11******** *************@2 2g2000hsm.googl egroups.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: cboRequestDueSe arch
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 cboRequestDueSe arch_AfterUpdat e()
Dim strSQL As String
If IsNull(Me.cboRe questDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingLis t"
Else
strSQL = "SELECT DISTINCTROW MailingList.* FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.Ma ilingListID = Donations.Maili ngListID " & _
"WHERE Donations.Reque stDue = " & Me.cboRequestDu eSearch & ";"
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
On Jul 13, 5:23 am, "Allen Browne" <AllenBro...@Se eSig.Invalidwro te:
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.Reque stDue = " & _
Format(Me.cboRe questDueSearch, "\#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" <OatBoatBaBoatB oatMcBoatNut... .@gmail.comwrot e in message
news:11******** *************@2 2g2000hsm.googl egroups.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: cboRequestDueSe arch
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 cboRequestDueSe arch_AfterUpdat e()
Dim strSQL As String
If IsNull(Me.cboRe questDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingLis t"
Else
strSQL = "SELECT DISTINCTROW MailingList.* FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.Ma ilingListID = Donations.Maili ngListID " & _
"WHERE Donations.Reque stDue = " & Me.cboRequestDu eSearch & ";"
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.Reque stDue = " & _
Format(Me.cboRe questDueSearch, "\#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
Hi,
try adding a Me.Requery after the 'Me.RecordSourc e = strSQL' and
before the 'End If' statement
Me.RecordSource = strSQL
End If
bobh.
On Jul 13, 11:45 am, Katherine
<OatBoatBaBoatB oatMcBoatNut... .@gmail.comwrot e:
On Jul 13, 5:23 am, "Allen Browne" <AllenBro...@Se eSig.Invalidwro te:
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.Reque stDue = " & _
Format(Me.cboRe questDueSearch, "\#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" <OatBoatBaBoatB oatMcBoatNut... .@gmail.comwrot e in message
news:11******** *************@2 2g2000hsm.googl egroups.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: cboRequestDueSe arch
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 cboRequestDueSe arch_AfterUpdat e()
Dim strSQL As String
If IsNull(Me.cboRe questDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingLis t"
Else
strSQL = "SELECT DISTINCTROW MailingList.* FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.Ma ilingListID = Donations.Maili ngListID " & _
"WHERE Donations.Reque stDue = " & Me.cboRequestDu eSearch & ";"
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.Reque stDue = " & _
Format(Me.cboRe questDueSearch, "\#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 -
On Jul 13, 1:26 pm, bobh <vulca...@isp.c omwrote:
Hi,
try adding a Me.Requery after the 'Me.RecordSourc e = strSQL' and
before the 'End If' statement
Me.RecordSource = strSQL
End If
bobh.
On Jul 13, 11:45 am, Katherine
<OatBoatBaBoatB oatMcBoatNut... .@gmail.comwrot e:
On Jul 13, 5:23 am, "Allen Browne" <AllenBro...@Se eSig.Invalidwro te:
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.Reque stDue = " & _
Format(Me.cboRe questDueSearch, "\#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" <OatBoatBaBoatB oatMcBoatNut... .@gmail.comwrot e in message
>news:11******* **************@ 22g2000hsm.goog legroups.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: cboRequestDueSe arch
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 cboRequestDueSe arch_AfterUpdat e()
Dim strSQL As String
If IsNull(Me.cboRe questDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingLis t"
Else
strSQL = "SELECT DISTINCTROW MailingList.* FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.Ma ilingListID = Donations.Maili ngListID " & _
"WHERE Donations.Reque stDue = " & Me.cboRequestDu eSearch & ";"
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.Reque stDue = " & _
Format(Me.cboRe questDueSearch, "\#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
On Jul 13, 4:05 pm, Katherine
<OatBoatBaBoatB oatMcBoatNut... .@gmail.comwrot e:
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.Reque stDue = #" & Me.cboRequestDu eSearch & "#;"
It worked. That might make yours work.
If not, try a separate query using the following SQL:
SELECT Donations.Reque stDue, Forms!MailingLi st.cboRequestDu eSearch AS
FormDate FROM MailingList INNER JOIN Donations ON
MailingList.Mai lingListID = Donations.Maili ngListID;
Note: Do this with the MailingList form open and with a value selected
for cboRequestDueSe arch. 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********@Fort uneJames.com
On Jul 13, 5:15 pm, CDMAPos...@Fort uneJames.com wrote:
On Jul 13, 4:05 pm, Katherine
<OatBoatBaBoatB oatMcBoatNut... .@gmail.comwrot e:
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.Reque stDue = #" & Me.cboRequestDu eSearch & "#;"
It worked. That might make yours work.
If not, try a separate query using the following SQL:
SELECT Donations.Reque stDue, Forms!MailingLi st.cboRequestDu eSearch AS
FormDate FROM MailingList INNER JOIN Donations ON
MailingList.Mai lingListID = Donations.Maili ngListID;
Note: Do this with the MailingList form open and with a value selected
for cboRequestDueSe arch. 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...@Fort uneJames.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
On Jul 16, 12:43 pm, Katherine
<OatBoatBaBoatB oatMcBoatNut... .@gmail.comwrot e:
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 cboRequestDueSe arch_AfterUpdat e()
Dim strSQL As String
If IsNull(Me.cboRe questDueSearch) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "MailingLis t"
Else
strSQL = "SELECT Donations.Reque stDue FROM MailingList " & _
"INNER JOIN Donations ON " & _
"MailingList.Ma ilingListID = Donations.Maili ngListID " & _
"WHERE Donations.Reque stDue = " & Chr(34) & Me.cboRequestDu eSearch
& 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 cboRequestDueSe arch 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********@Fort uneJames.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 from queries. Let me just add that Allen Browne excellent
article about this subject may not apply to this scenario on an
elementary level. (Here's the link to the article; Filter a Form on a
Field in a Subform -...
|
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 the first
subform by their shared key field.
Browsing in that arrangement works beautifully.
Now, the third tier is the line item data, and there are a number of
different kinds of line items sharing the same table -- specifically,
there...
|
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. I can do this the
first time the form loads.
|
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 in a datasheet format.
So far…
1)I have created a query called "CatFilterQuery" which results in a
prompt to enter the "category field" to filter on.
2)Created a macro called "FilterCategory" which is based on the query
mentioned above and uses...
|
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 user enters the
last qualifying field on the main form.
In one case this works fine, the subform shows the data the user wants
to update -- which means showing all the data put in previously (ie
showing this via the requery and the continuous...
| |
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 record
source that returns an ID field and a Text field.
Next to each combo box is two buttons, one that 'Applys' the filter of
the sub-form to the value in the combo box and one that 'Clears' the
form's current filter.
When the click event of the...
|
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 by form" feature. When
the user tries to use Filter by form a messagebox is displayed: "There
are too many controls in this form to perform a filter by form", after
that,when the user exit the Filter by Form mode, Access crash,
displaying a...
|
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 generate the
necessary data and you can also addtionally filter by by individual
department/s, supplier/s if you so wish which is great
However, I'm trying to develop an individual statistical form that for
one subform uses the date filter as...
|
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 = 'product')
I've not used an In clause before. Thanks a lot for the education.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |