473,385 Members | 1,333 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,385 software developers and data experts.

Filter SubForm by changing query criteria

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 4103
puppydogbuddy
1,923 Expert 1GB
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 Expert 2GB
Are you sure the query returns any records?
Did you run it in query builder?
Dec 12 '07 #3
NeoPa
32,556 Expert Mod 16PB
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,556 Expert Mod 16PB
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
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 Expert 1GB
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,556 Expert Mod 16PB
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
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,556 Expert Mod 16PB
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
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: 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...
1
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...
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...
3
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...
0
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...
14
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....
14
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...
1
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.