Results 1 to 3 of 3
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Dynamic control source for textbox

    I have a crosstab query with column headers stylised as "ABC_2024", "ABC_2023", etc.

    In a report linked to the query, I have a textbox that I want the control source to always be linked to the field "ABC_(previous year)". So for this year, it'd be "ABC_2023". But once it turns 1/1/2025, the control source automatically links to "ABC_2024" instead of me having to manually change it. Is there a way to achieve this?

    I (stupidity) tried putting this in the control source:



    Code:
    ="ABC_" & Year(Date())
    But this just displays "ARO_2023" in the control source rather than the value from the query. Maybe it's not possible but I thought I'd check. Thanks!

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Do it in the Open event of the report:
    Code:
    Private Sub Report_Open(Cancel As Integer)
    Me.txtPrevYear.ControlSource = "ABC_" & Year(Date())-1
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Thank you! That worked!

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

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2021, 02:35 PM
  2. Replies: 9
    Last Post: 12-15-2016, 07:31 PM
  3. Textbox Control Source
    By asmores in forum Access
    Replies: 5
    Last Post: 02-19-2015, 09:59 AM
  4. Replies: 8
    Last Post: 07-30-2012, 04:43 PM
  5. Replies: 17
    Last Post: 02-08-2012, 10:06 AM

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