473,698 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filter SubForm by changing query criteria

52 New Member
Hello everyone. i have a fom and subform (they are not linked).The subform has a date field named StartDate. i have a button on the form that when clicked will change the recordset of the subform to show StartDate of today. When i hit the command button, the subform becomes blank.Its driving me crazy.Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdToday_Click()
  2.  
  3. Dim sSQL As String
  4.  
  5. sSQL = "SELECT * FROM QueryCases WHERE QueryCases.StartDate =  Date()"
  6.  
  7. Forms!ViewCases![ViewCasesSubform].Form.RecordSource = sSQL
  8.  
  9. End Sub
Dec 12 '07 #1
9 4120
puppydogbuddy
1,923 Recognized Expert Top Contributor
Hello everyone. i have a fom and subform (they are not linked).The subform has a date field named StartDate. i have a button on the form that when clicked will change the recordset of the subform to show StartDate of today. When i hit the command button, the subform becomes blank.Its driving me crazy.Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdToday_Click()
  2.  
  3. Dim sSQL As String
  4.  
  5. sSQL = "SELECT * FROM QueryCases WHERE QueryCases.StartDate =  Date()"
  6.  
  7. Forms!ViewCases![ViewCasesSubform].Form.RecordSource = sSQL
  8.  
  9. End Sub

Date() is an embedded function, that needs to be exposed as a parameter within the SQL string. Try the syntax this way.
Expand|Select|Wrap|Line Numbers
  1. sSQL = "SELECT * FROM QueryCases WHERE QueryCases.StartDate = " &  Date()
Dec 12 '07 #2
FishVal
2,653 Recognized Expert Specialist
Are you sure the query returns any records?
Did you run it in query builder?
Dec 12 '07 #3
NeoPa
32,569 Recognized Expert Moderator MVP
As pDog says, you need the RESULTS of the Date() function added to your SQL string (IE it is for VBA to resolve not for the SQL interpreter). However, as a date literal, it should also be enclosed in '#' characters and formatted in M/D/Y format for SQL (See Literal DateTimes and Their Delimiters (#).).
Expand|Select|Wrap|Line Numbers
  1. sSQL = "SELECT * " & _
  2.        "FROM QueryCases " & _
  3.        "WHERE [StartDate] = " & Format(Date(), '\#m/d/yyyy\#')
Dec 12 '07 #4
NeoPa
32,569 Recognized Expert Moderator MVP
Actually, I just ran some tests and, certainly for me, the SQL interpreter DOES resolve Date() correctly when done as you have done. This means it doesn't need to be treated as a literal (it still can be but shouldn't NEED to be). I can't see what's wrong with your SQL. Is it possible that the reference to the control is wrong (even then, why would it change at all if the reference were wrong)? Anyway, in case it helps, check out Referring to Items on a Sub-Form.
Dec 12 '07 #5
darnnnel
52 New Member
Thank you so much for your help. do you think you could look at my file. i couldnt attach it here, it is too large - the link is below. i would really appreciate it.

www.imperialelevatorcorp.com/download/date.zip
Dec 12 '07 #6
puppydogbuddy
1,923 Recognized Expert Top Contributor
Thank you so much for your help. do you think you could look at my file. i couldnt attach it here, it is too large - the link is below. i would really appreciate it.

www.imperialelevatorcorp.com/download/date.zip
I downloaded your file, but could not open it because I have Access 2000 and you must have Access 2003. Sorry.
Dec 13 '07 #7
NeoPa
32,569 Recognized Expert Moderator MVP
If you leave instructions as to where to look inside the database (You haven't referred to any query by name), and the db is 2003 & not 2007, then I'll have a look for you from home (when I get there of course). I'd rather not spend ages just hunting around for the relevant part of the database though.
Dec 13 '07 #8
darnnnel
52 New Member
Thanks guys i got it - here is the code:
Expand|Select|Wrap|Line Numbers
  1. Dim sSQL As String
  2.     Dim viewToday
  3.     viewToday = Format(Now(), "mm/dd/yyyy")
  4.  
  5.     sSQL = "SELECT * FROM QueryCases WHERE QueryCases.StartDate = #" & viewToday & "#;"
  6.     Me![ViewCasesSubform].Form.RecordSource = sSQL
Dec 13 '07 #9
NeoPa
32,569 Recognized Expert Moderator MVP
You're welcome :)
And thanks for letting us know - you saved me a job later ;)
Dec 13 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
7848
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 -...
2
9797
by: Andante.in.Blue | last post by:
Hi everyone! I was wondering if there is a away to use Access 97's build in filter-by-form function but restrict its effect to just the subform. I have a parent form that shows the major divisions of the company, and a subform that is linked so that it displays all the jobs within the division in the parent form. I also want the ability to filter the subform, so the users can pick out a bunch of common jobs easily. I did this using a...
1
2234
by: Colin | last post by:
I created a macro that starts a filter on a query. The criteria in the query is: Like & "*" The macro is initiated by pressing a command button on the form. This works fine. However, when this form becomes an unbound subform of another main form, I'm prompted twice for the value of the filter (i.e. the group name to enter). How can I stop the double prompt when my form is used
4
7013
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...
3
11961
by: dhowell | last post by:
In reading some of the posts on this group, it appears as though it is not strait forward at all to filter a form, which has subforms, by criteria which are either on subforms or span more than one subform..... This MSDN article however makes it sound as simple as clicking "Filter by Form", entering the search criterial in the form and/or it's subforms, then just clicking "Apply Filter"...... ...
0
346
by: bcreighton | last post by:
I have created a bound subform on an unbound masterform linked together with a common field (A store's identification number) using an unbound combobox on the masterform and an invisible field on the subquery, which filters for a particular store. The subform is in continuous mode. So, what you see when you select a store is a list of all the items that that have not been billed for. There is a simple yes no field that filters out all...
14
11462
by: Kurt | last post by:
I have an unbound main form with an unbound subform. frmProjects fsubProjectList Using combo boxes, the user can select several search criteria on frmProjects and then click a command button. The command button passes the criteria as a string to a query. A subform, which is based on this query, shows the results of the search.
14
4086
by: Anja | last post by:
Hi everyone, I have a sub form that references a query to get the results. However, what I want to do is filter the results further based on a certain criteria. How can I tell the sub form to filter results based on a certain criteria. I tried using the Filter and OrderBy fields in the designer but they seem to have no affect!
1
2843
by: Barb.Richards | last post by:
I have created an append query that pulls information from one database, and will append the selected information into a new table. The fields are setup like 'number' 'category' 'code' 'shares' and 'dollars'. Using the "backend" of this table I can filter the numbers by right clicking and using Filter For: then enter 1 or 2 or 3 and this will return results for all information that has 1 or 2 or 3 as a number. However, the problem I...
2
4203
by: Matthew Wells | last post by:
Hi there. I am a programmer for a living, but this problem has my whole team stumped. I have a subform based on a query. I'm not using the "LinkMaster/ChildFields" properties ( I have my reasons ). The ssbform's query has a criteria for forms!masterform!Keyfield. This works fine on open. I have an options group with two options - True or All. Selecting True adds a filter to the subform's fitler property "Billed = True". That...
0
8674
marktang
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...
0
8603
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,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
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 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...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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();...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.