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: - Private Sub cmdToday_Click()
-
-
Dim sSQL As String
-
-
sSQL = "SELECT * FROM QueryCases WHERE QueryCases.StartDate = Date()"
-
-
Forms!ViewCases![ViewCasesSubform].Form.RecordSource = sSQL
-
-
End Sub
9 4103
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: - Private Sub cmdToday_Click()
-
-
Dim sSQL As String
-
-
sSQL = "SELECT * FROM QueryCases WHERE QueryCases.StartDate = Date()"
-
-
Forms!ViewCases![ViewCasesSubform].Form.RecordSource = sSQL
-
-
End Sub
Date() is an embedded function, that needs to be exposed as a parameter within the SQL string. Try the syntax this way. - sSQL = "SELECT * FROM QueryCases WHERE QueryCases.StartDate = " & Date()
Are you sure the query returns any records?
Did you run it in query builder?
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 (#).). - sSQL = "SELECT * " & _
-
"FROM QueryCases " & _
-
"WHERE [StartDate] = " & Format(Date(), '\#m/d/yyyy\#')
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.
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.
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.
Thanks guys i got it - here is the code: - Dim sSQL As String
-
Dim viewToday
-
viewToday = Format(Now(), "mm/dd/yyyy")
-
-
sSQL = "SELECT * FROM QueryCases WHERE QueryCases.StartDate = #" & viewToday & "#;"
-
Me![ViewCasesSubform].Form.RecordSource = sSQL
NeoPa 32,556
Expert Mod 16PB
You're welcome :)
And thanks for letting us know - you saved me a job later ;)
Sign in to post your reply or Sign up for a free account.
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
| |