Results 1 to 9 of 9
  1. #1
    wily_wolf is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2016
    Posts
    36

    Want checkbox selection [TRUE] to fill in date of earliest project in table.

    Hey, I currently have a checkbox that when checked [TRUE] fills in two textboxes with the dates 1/1/2016 and 12/31/2016.




    I would like the checkbox, when checked [TRUE], to fill in the first textbox with the earliest project date from my table, and the second textbox with the latest project date from my table. All in that certain year too. So, 2016 for instance.

    Here is the code I have so far. Need help with what the value would/could be.

    Code:
    Private Sub chk2016_Click()
        If Me.chk2016 = True Then
            Me.txtStart.Value = #1/1/2016#
            Me.txtEnd.Value = #12/31/2016#
        ElseIf Me.chk2016 = False Then
            Me.txtStart.Value = Null
            Me.txtEnd.Value = Null
            
        End If
        
    End Sub

    Thanks in advance.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    make a form, on the form is a textbox called txtYr to put the current year you want.
    make a query called , qs1Year, this reads the text box txtYr off the form and pulls the data.
    add an extra field to the query called Year, = year(projDate)

    the query would look like:
    select *, year(projDate) as Year from table where year(projDate) = forms!myForm!txtYr

    then

    Code:
    Private Sub chk2016_Click()
        If Me.chk2016 = True Then
            Me.txtStart.Value = dMin("[ProjDate]","qs1Year", "[year]=" & txtYr)
            Me.txtStart.Value = dMax("[ProjDate]","qs1Year", "[year]=" & txtYr)
        Else
            Me.txtStart.Value = Null
            Me.txtEnd.Value = Null
        End If    
    End Sub

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Those functions should be DMin and DMax, not Min and Max.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Oops,thx JohnG

  5. #5
    wily_wolf is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2016
    Posts
    36
    Great, I'll give that a try and get back to you.

  6. #6
    wily_wolf is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2016
    Posts
    36
    I found that this was a better approach to what I was thinking originally. I didn't really want to have people have to input a year into a textbox. Rather, I wanted them to just be able to select the "2016" checkbox and auto-fill the Start and End Date textboxes.

    Here's what I have for future reference:

    Code:
    Private Sub chk2016_Click()
        
        If Me.chk2016 = True Then
            Me.txtStart.Value = DMin("[ProjectDate]", "tblTimeTracker", "Year([ProjectDate])=" & "2016")
            Me.txtEnd.Value = DMax("[ProjectDate]", "tblTimeTracker", "Year([ProjectDate])=" & "2016")
        Else
            Me.txtStart.Value = Null
            Me.txtEnd.Value = Null
        End If
    End Sub
    Thanks for leading me to the answer though.

    Take care.
    Last edited by wily_wolf; 12-21-2016 at 01:19 PM. Reason: typo

  7. #7
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    make a form, on the form is a textbox called txtYr to put the current year you want.
    make a query called , qs1Year, this reads the text box txtYr off the form and pulls the data.
    add an extra field to the query called Year, = year(projDate)

    the query would look like:
    select *, year(projDate) as Year from table where year(projDate) = forms!myForm!txtYr

    then

    Code:
    Private Sub chk2016_Click()
        If Me.chk2016 = True Then
            Me.txtStart.Value = Min("[ProjDate]","qs1Year", "[year]=" & txtYr)
            Me.txtStart.Value = Max("[ProjDate]","qs1Year", "[year]=" & txtYr)
        Else
            Me.txtStart.Value = Null
            Me.txtEnd.Value = Null
        End If    
    End Sub

  8. #8
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    what are you gonna do in 2017?

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Much better would be a table... maybe "tblAvailableYears".
    Or a query that gets the distinct dates in field "ProjDate".
    Use an unbound combo box so the year could be selected. The combo box after update event could run code to get the min/max ProjDate dates for the year selected.
    You could even default the combo box to default to the current year and have a button execute the code to get the min/max ProjDate dates.


    Using a check box with the year as the field name means you have to modify forms, queries, reports & code when the year changes.

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

Similar Threads

  1. Replies: 1
    Last Post: 03-21-2016, 07:32 PM
  2. Replies: 2
    Last Post: 10-28-2014, 03:55 AM
  3. Replies: 3
    Last Post: 03-08-2013, 11:34 AM
  4. if checkbox= true subtract 8.75 from A to=B
    By VanillaAwesome in forum Queries
    Replies: 6
    Last Post: 07-28-2012, 12:48 PM
  5. Replies: 1
    Last Post: 11-03-2011, 11:56 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