Results 1 to 9 of 9
  1. #1
    nurul is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    37

    search records by month and year

    hye all,



    i would like to ask is there anyone know how to search records by month and year.
    example i will have form that contain combobox that will list Jan-Dec.
    and also unbound box for user to enter the year.

    then, it will have search button. after the user click search button, it will show report of the selected month and year..

    anyone know how can i get something like this..??

    your help is much appreciate.

    thank in advance.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    Presume you have a date/time field in table. Consider:

    SELECT * FROM tablename WHERE Year([datefield]) & Format([datefield],"mmm") = [input year] & [input month];

    Or:

    DoCmd.OpenReport "reportname", , "Year([datefield]) & Format([datefield],'mmm') = '" & Me.[yeartextbox] & Me.[monthtextbox] & "'";
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    nurul is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    37
    thank June7 for reply..

    let me make clear of this..
    this code i need to paste at query or else..?

    SELECT * FROM tablename WHERE Year([datefield]) & Format([datefield],"mmm") = [input year] & [input month];

    and the other one at search button..?am i right..?

    DoCmd.OpenReport "reportname", , "Year([datefield]) & Format([datefield],'mmm') = '" & Me.[yeartextbox] & Me.[monthtextbox] & "'";


    thank in advance

  4. #4
    nurul is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    37
    i already make use of the code that u give to me..

    the problem is, when i search, instead showing the report in tab, it will automatically print the report..
    i don't why it just print without showing the report first..as i see the code is DoCmd.OpenReport so, mean it will open the report not just print the report.

    any idea about this..?

    thank in advance.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    DoCmd.OpenReport "reportname", , acViewPreview, "Year([datefield]) & Format([datefield],'mmm') = '" & Me.[yeartextbox] & Me.[monthtextbox] & "'";
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    nurul is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    37
    thank June7, it work great now..

    if you don't mind, i want to ask how to set the report instead after we search it show in print preview, it will show in report view itself..?

    thank in advance

  7. #7
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536

  8. #8
    nurul is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    37
    thank alansidman.

    it show in report view now..

    but i think something is wrong here..i don't know why..even if i select for example dec, it will show all the records that in my db..
    this code is correct right..?

    DoCmd.OpenReport "historyReport", acViewReport, "Year([date_taken]) & Format([date_taken],'mmm') = '" & Me.[TextYear] & Me.[comboMonth] & "'"

    i put it in my search button event procedure..?

    thank in advance

  9. #9
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 07-30-2012, 11:55 AM
  2. Sorting by month and day - without year
    By TracyBell in forum Access
    Replies: 3
    Last Post: 11-17-2011, 10:29 AM
  3. show records in this month last year?
    By geoffcox in forum Queries
    Replies: 4
    Last Post: 06-11-2011, 07:12 AM
  4. Replies: 0
    Last Post: 03-25-2011, 02:37 PM
  5. by year by month
    By nkuebelbeck in forum Reports
    Replies: 21
    Last Post: 03-24-2010, 01:53 PM

Tags for this Thread

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