Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    115

    prompt for month and year in a date field


    I have a hire date field that is mm/dd/yyyy, how to I create a prompt in this field to get all the people hired in any month/year combination?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    21,691
    It wouldn't be the most efficient, but:

    WHERE Month(FieldName) = Forms!... AND Year(FieldName) = Forms!...

    Personally I'd extrapolate the start/end dates from the input and have the query use those:

    WHERE FieldName Between Forms!... And Forms!...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,572
    Code:
    SELECT tbl1.[Field1], tbl1.[Field2], Year([SomeDateField]) AS Exp1, Month([SomeDateField]) AS Expr2
    FROM tbl1 WHERE (((Year([SomeDateField]))=2020) AND ((Month([SomeDateField]))=10))
    If you want prompts for the year and date, use a prompt inside of brackets e.g. [TheMonth] instead of 10
    Obviously you have to use your own table and field names. Untested, but should work.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  4. #4
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,687
    If you only have a small number of records, then using the Month and Year suggestions made by both pbaldy and Micron should work OK
    However, that approach won't allow Access to make use of any indexes on the date fields so will be very slow for a large dataset.

    I would recommend the second approach Paul suggested as it will make use of date indexes and be much faster especially for large datasets.
    To use this, lets take an example. Say the user selects October and 2019, then filter for all dates between the first and last days of that month : 01/10/2019 & 31/10/2019.
    This can be easily done using code
    For more info, see my article on optimising queries http://www.mendipdatasystems.co.uk/s...s-8/4594556613
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  5. #5
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    115
    The query has two different date sets a user might want to query, fiscal year/period or month/year to see different data. Would a form allow for one or the other to be used?

  6. #6
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,687
    Yes. Have two different date selectors available.
    My Incident Analysis example app includes multiple different ways of selecting date ranges:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	20 
Size:	92.4 KB 
ID:	43793
    If interested in knowing more, its available at http://www.mendipdatasystems.co.uk/m...ter/4594454290
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  7. #7
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    115
    isladogs, this link goes to an advertisement, are you selling your solution/app?

  8. #8
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,687
    Hi.
    Sorry something went wrong with my webhost names.co.uk and the links went astray earlier. The page you may have seen was for the webhost.
    It should be OK again now. I'd be grateful if you could check & let me know.
    The example app in the link is completely free
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  9. #9
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    115
    I did try again and it still goes to the webhost page

  10. #10
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,687
    Hmm, its working for me...
    Let me try the link again...http://www.mendipdatasystems.co.uk/m...ter/4594454290.

    If it still fails for you, click my website link below or go to www.mendipdatasystems.co.uk then Downloads...Example Databases...Multiple Group and Filter
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  11. #11
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    115
    all links go to medipdatasystems.co.uk Is there any chance you could zip and attach it here? Thanks

  12. #12
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,687
    Quote Originally Posted by smg View Post
    all links go to medipdatasystems.co.uk Is there any chance you could zip and attach it here? Thanks
    Hmm....my website is www.mendipdatasystems.co.uk and the page you want is http://www.mendipdatasystems.co.uk/m...ter/4594454290. It should look like this:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	17 
Size:	197.6 KB 
ID:	43794

    If you do see that, you want the Incident Analysis example further down the page.
    However, if you still get this...
    Click image for larger version. 

Name:	Capture.jpg 
Views:	17 
Size:	83.9 KB 
ID:	43795
    then I need to contact my webhost & will upload the file here as requested

    P.S. Apologies for the hassle ...and the huge images
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  13. #13
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    115
    yes please upload as nothing above DON'T LET THIS SPACE GO TO WASTE appears from any of the links provided. Thanks!

  14. #14
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,687
    Thanks. I've just contacted my webhost but its likely to be an issue for a few days at least due to the New Year.
    The file is now attached. Hope it was worth the wait....

    FWIW: The link below is to an archive of that webpage that I saved yesterday ... courtesy of the Internet Archive:
    Multiple Group & Filter - Mendip Data Systems (archive.org)
    Hopefully that does work for you
    Attached Files Attached Files
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  15. #15
    Welshgasman is offline Expert
    Windows 10 Access 2007
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    622
    Archive works for me?
    Please, please use # when posting code snippets.
    Cross Posting Etiquette: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?search_query=debug+access+vba



Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 05-03-2017, 09:48 AM
  2. Get month and year from date
    By shayen in forum Programming
    Replies: 3
    Last Post: 09-21-2016, 03:04 AM
  3. Replies: 4
    Last Post: 05-26-2013, 03:28 PM
  4. Year to DATE by Month
    By lugnutmonkey in forum Queries
    Replies: 1
    Last Post: 01-18-2013, 05:37 PM
  5. month year date
    By slimjen in forum Database Design
    Replies: 6
    Last Post: 04-17-2012, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums