Results 1 to 9 of 9
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Open form to month or year

    I'm hoping to make a form open to a specific month, current month or the year typed in an unbound textbox on a form

    I have one unbound textbox

    one button with current month

    and one with current year

    not sure on the vba

    DoCmd.OpenForm "frmSchoolCatalogues", , , "CatalogueLabelPrinted = Month(Now())"



    CatalogyeLabelPrinted is a date field.

    I'm hoping that something like

    DoCmd.OpenForm "frmSchoolCatalogues", , , "CatalogueLabelPrinted = Year(Now())"

    will work for year

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Need to extract the month or year from the field value.

    DoCmd.OpenForm "frmSchoolCatalogues", , , "Month(CatalogueLabelPrinted) = Month(Now())"

    But that will pull records from every year. Consider:

    DoCmd.OpenForm "frmSchoolCatalogues", , , "Year(CatalogueLabelPrinted)=Year(Date()) AND Month(CatalogueLabelPrinted) = Month(Now())"
    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
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    ok makes sense

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Works like a charm thanks!

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Need to extract the month or year from the field value.

    DoCmd.OpenForm "frmSchoolCatalogues", , , "Month(CatalogueLabelPrinted) = Month(Now())"

    But that will pull records from every year. Consider:

    DoCmd.OpenForm "frmSchoolCatalogues", , , "Year(CatalogueLabelPrinted)=Year(Date()) AND Month(CatalogueLabelPrinted) = Month(Now())"
    How would you pass the value from the unbound textbox on the form?

    DoCmd.OpenForm "frmSchoolCatalogues", , , "Year(CatalogueLabelPrinted)=Year(forms!frmDateCat alogues!Text4)"

    or DoCmd.OpenForm "frmSchoolCatalogues", , , "Year(CatalogueLabelPrinted)= & Year(me.Text4)"

    ??

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Do not place variables within quote marks. Concatenate variables. Reference to textbox is a variable.

    DoCmd.OpenForm "frmSchoolCatalogues", , , "Year(CatalogueLabelPrinted)=" & Year(forms!frmDateCatalogues!Text4)

    DoCmd.OpenForm "frmSchoolCatalogues", , , "Year(CatalogueLabelPrinted)=" & Year(Me.Text4)
    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.

  7. #7
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    DoCmd.OpenForm "frmSchoolCatalogues", , , "Year(CatalogueLabelPrinted)=" & Me.Text4

    I used this and it works great (I'm still yet to figure out date range - I will see if I can work that out myself first before asking)


    eh,

    this is as far as I got and it's not working...

    DoCmd.OpenForm "frmSchoolCatalogues", , , "CatalogueLabelPrinted BETWEEN" & Me.txtBefore & "AND" & Me.txtAfter

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Date values need # delimiter. And don't forget spaces so text doesn't run together when concatenated.


    DoCmd.OpenForm "frmSchoolCatalogues", , , "CatalogueLabelPrinted BETWEEN #" & Me.txtBefore & "# AND #" & Me.txtAfter & "#"
    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.

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    oh ok, I did see that online but didn't realise... thanks!

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

Similar Threads

  1. Replies: 4
    Last Post: 05-26-2013, 03:28 PM
  2. Filter Form records By Month Year
    By maxmaggot in forum Forms
    Replies: 4
    Last Post: 04-05-2013, 06:34 PM
  3. Sum by Won Project in by each month of the year
    By 011billyw in forum Reports
    Replies: 11
    Last Post: 03-22-2012, 04:09 PM
  4. default month and year
    By beefyalby in forum Forms
    Replies: 3
    Last Post: 12-05-2010, 11:40 PM
  5. by year by month
    By nkuebelbeck in forum Reports
    Replies: 21
    Last Post: 03-24-2010, 01:53 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