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

How to filter a "shortdate" in query from a "longdate" in subform

547 512MB
Use Access 2007;
"Admit" field in "SfAdmit" subform is a "long date" and the date format here is ddmmyyyy with time and seconds.

I created a short date unbound textbox in this same subform called "admit1" which is set to shortdate ddmmyyyy as i want to use this to filter a query.

Expand|Select|Wrap|Line Numbers
  1. Form + Subform + short date path from query  = [Forms]![frmAdmit]![sfAdmit]![admit1]
The "RxDate" field in the query is in "short date" format ddmmyyyy", where i add the above code in the criteria block.

Problem - it does not filter my query data based on the subform "admit1" field i use.
Any suggestions please?
Jan 24 '14 #1

✓ answered by zmbd

The trouble comes from the fact that the date/time field always stores a time #01/25/2014 00h00# so the short date will show just #01/25/2014# so if the time stored is actually #01/25/2014 00h00:01# and you search on #01/25/2014# it wont return, etc...

So here's what I do when I don't care about times and I want something fairly easy without a lot of VBA.

Query, calculated field
zdatevalue: DateValue([datefield_mmddyyyy])
(caution with the datevalue, it returns a value that reflects the current system shortdate)

In the form I set two text boxes, with the format set to shortdate; thus, I know that the format returned should work with the calculated field.

Now in the criteria in the calculated field use your between
Between [Forms]![tbl_datatype]![Text17] And [Forms]![tbl_datatype]![Text22]

There are other methods with VBA and the like; however in the Query editor this is the easiest I've found. I am; however, always open to more and better methods.

6 1785
zmbd
5,501 Expert Mod 4TB
Form + Subform + short date path from query = [Forms]![frmAdmit]![sfAdmit]![admit1]


That first section (Form + Subform + short date path from query) isn't valid; thus, what are you actually using? (or maybe I'm being a bit obtuse - dealing with three littleones under 5 today (^_^) )

Also keep in mind if you use the "##" deliminators, Access expects the "#mm/dd/yyyy#" internally. Allen Browne: International Dates You may also need to use the BETWEEN to get the proper dates from ones with date and time. I tend to use a query to strip the time portion off and return just the date in a calculated field. Perhaps a bit of a kludge?!

Your subform reference appears wierd (Allen Browne: Referring to Controls on a Subform) try this version:
Forms.frmAdmit.sfAdmit.Form.admit1
some will argue with the dot/bang for that last so try this construct:
Me!Subform1.Form!ControlName
and if you are using the ACC2010-Navigation control use the bang.

THis is the reference I will use when I get lost:
Forms: Refer to Form and Subform properties and controls
I'm worried enough that this site might ever go down that I took advantage of the download offer of a hardcopy of the table - upper right hand corner!
Jan 24 '14 #2
neelsfer
547 512MB
Thx ZMBD
Apologies it is not long date but "general date" format that is causing issues.
This is what i am trying to explain in pictures.
Admit1 is derived by using =Admit in the control source in an unbound textbox, and setting the format to "Short date". (the Admit field is in "general date" format)

I would use "between" as soon as i get this to work and filter the query.

What i have noticed is if i try and filter this query from a different (short date) "date field" that also exists in this same subform, then it works great.

It only refuses to read the "Admit1"(Short date) field derived from the "Admit" field (general date) in the same subform.

Maybe i need to use a different way to create the short date from the general date on this same subform.

My reason for doing all of this is to create an invoice using a date range, based on the period the person was in a hospital and all medicines supplied in this period, between the admit and discharge dates.

Suggestions?



Attached Images
File Type: jpg subform.jpg (51.4 KB, 621 views)
File Type: jpg query.jpg (40.7 KB, 642 views)
Jan 25 '14 #3
zmbd
5,501 Expert Mod 4TB
Just for giggles insert ">=" before the form control in the query parameter (ie: >=[Forms]![tbl_datatype]![Text17].

If that doesn't change anything then change the ">" to "<" I've a suspicion that theres a time bug attached that you are not seeing... how is the format being set in [admit1]

If either of these work then something like:
DateValue([datefield_mmddyyyy])=DateValue([Forms]![tbl_datatype]![Text17])
Enter this in the same place you entered the other criteria (be aware of the fact that datevalue() works on the shortdate format of the PC at system level)
Jan 25 '14 #4
neelsfer
547 512MB
You are a star ZMBD, it works.

To use it with "admit1" and "discharge1" fields to see any transaction between the 2 dates, how would i incorporate the ">=" ?
Expand|Select|Wrap|Line Numbers
  1. Between [Forms]![frmAdmit]![sfAdmit]![admit1] and [Forms]![frmAdmit]![sfAdmit]![discharge1]
this does not work
Expand|Select|Wrap|Line Numbers
  1. >=[Forms]![frmAdmit]![sfAdmit]![admit1] And <=[Forms]![frmAdmit]![sfAdmit]![discharge1]
Jan 25 '14 #5
zmbd
5,501 Expert Mod 4TB
The trouble comes from the fact that the date/time field always stores a time #01/25/2014 00h00# so the short date will show just #01/25/2014# so if the time stored is actually #01/25/2014 00h00:01# and you search on #01/25/2014# it wont return, etc...

So here's what I do when I don't care about times and I want something fairly easy without a lot of VBA.

Query, calculated field
zdatevalue: DateValue([datefield_mmddyyyy])
(caution with the datevalue, it returns a value that reflects the current system shortdate)

In the form I set two text boxes, with the format set to shortdate; thus, I know that the format returned should work with the calculated field.

Now in the criteria in the calculated field use your between
Between [Forms]![tbl_datatype]![Text17] And [Forms]![tbl_datatype]![Text22]

There are other methods with VBA and the like; however in the Query editor this is the easiest I've found. I am; however, always open to more and better methods.
Jan 25 '14 #6
neelsfer
547 512MB
Thx a million ZMBD. I have wasted 3 evenings, and with your help it is working now!
Jan 25 '14 #7

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

Similar topics

2
by: espositozero | last post by:
Hello... I'm REALLY new to this whole thing, so if you all don't mind speaking in lamens terms for me... What I want to do seems like it should be simple, but I've been searching everywhere and I...
3
by: russellhq | last post by:
Hi, I'm fairly new to access and have a little trouble with a crosstab query I've setup. I have a main form where the user selects a project name and below in a subform, a crosstab query is...
0
by: sandy21380 | last post by:
I have the following code in my program allowing users to search for entries matching up to five different criteria at once. I changed the form to now contain a subform and would like to allow the...
23
by: mforema | last post by:
Hi everybody, I need to create a query that will search based on keywords and major categories. My tables are set-up as follows: tblLiteratureArticles: Abbreviation(FK) ArticleID(PK) Author...
9
by: angi35 | last post by:
Hi - In Access 2000, I have a form I want to filter, but I can't get the syntax right in the code. Form: Subform: Control on : txtStart Nested Subform on : Control on : txtSDate
1
by: nagileon | last post by:
Hi there The code is working fine but I don't know how to show the output of: "select count(leads.id) from leads". I did put the "Subform/Subreport" control on the Form but have no idea what...
0
by: Kassimu | last post by:
Hi all, I have a table which has a subdatasheet. I need to create the query that will have additional field(s) for each record in sub datasheet. How can I create such a query? To bring in the...
4
by: MLH | last post by:
If I have a main form - Form3 - with a subform control named SF4 and they are NOT linked on any common field (no child or master field links) - can I write code on Form3 to filter the records...
10
by: edgalljr | last post by:
I have a Button on a form that filters on 2 fields using the following code: Private Sub cmd_NavyDue_Click() With Me .FilterOn = True DoCmd.ApplyFilter , " = 'NAVY' And >1" Me.OrderBy =...
4
by: Pierkes | last post by:
Hi, Ik have a form on which the user can fillin a few field that are used to filter a query to make a report. On the form is also a button to run the report in preview mode. The fields used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
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
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,...
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...

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.