Auto Date in form "pages"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • frys
    New Member
    • Dec 2007
    • 29

    Auto Date in form "pages"

    I have a form set up like a journal

    the top of the page has

    2 fields

    dateID {autonumber)
    Date (date/time)

    under these there is a subform with ny notes section

    i would like to have the date change from todays date to tommorrows date on the next page

    how do i do this
  • janders468
    Recognized Expert New Member
    • Mar 2008
    • 112

    #2
    This depends on what you mean by change page, and how you are doing that. It sounds like you need to respond to whatever event a page change is and populate the appropriate control or record with today's date. the Functions Now or Date will return today's date. If you add a few more details we can probably zero in on what you need.

    Comment

    • frys
      New Member
      • Dec 2007
      • 29

      #3
      first off thanks for replying


      2nd

      i think what i am getting at is

      i want 2 forms. they are:

      1 main for and a sub form
      on the main form i have a date box call it txt_date
      further down the form is a sub form called Subform_Memo

      when ever i click to a new record on the main form i want the date to be 1 day after the last record

      i never want a day to be missed so a default value of Date() wont work. also i never want a date to repeat so there should never be 2 December 29 2008 ... so i indexed the field making duplicates allowed (no)

      they real issue i have is that the next record of the main form as of writing is not taking the next possible day ie December 30th 2008

      i hope im being clear enough i am having trouble explaining it:)

      if i click new record 3 times in a row the date should change from
      December 29
      December 30
      december 31

      etc even if the date is december 29th

      Comment

      • janders468
        Recognized Expert New Member
        • Mar 2008
        • 112

        #4
        You can create a variable that holds today's date when the form opens. Then whatever triggers a new record or page change can increment this variable i.e.
        Code:
        dim dte as date
        sub form_open
             dte = date
        end sub
        
        sub newpage()
             dte = dte + 1
        end sub
        If today's date is too general as a starting point you can populate the variable from wherever you are storing the dates (i.e. the maximum date value from the table the dates are contained in).
        Hopefully I understood you correctly, if not, let me know and I'll try again ;-)

        Comment

        • frys
          New Member
          • Dec 2007
          • 29

          #5
          hate to sound new to VbA but it has been a while

          If i put that code in the On load event i get an error.

          i dim dte as date over the sub
          enter the code in the sub and then end the sub

          but it is popping up error

          i should pull out my books and reread the coding sections


          but it looks like that might work.. only thing i want it to do is call the last date entered and add 1 day so i never miss a day even if i havent opened it in 3 days i need to be forced to fill in the missing days

          Comment

          • janders468
            Recognized Expert New Member
            • Mar 2008
            • 112

            #6
            What does the error message say?

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              I think this will do the job. Where

              TableDateField is the field that txt_Date is bound to

              and

              YourTable is the actual name of your underlying table

              Code:
              Private Sub Form_Current()
              If Me.NewRecord Then
                If IsNull(DMax("[TableDateField]", "YourTable")) Then
                 Me.txt_Date = Date
                Else
                 Me.txt_Date = DMax("[TableDateField]", "YourTable") + 1
                End If
              End If
              End Sub
              Linq ;0)>

              Comment

              Working...