Querying dates of two fields.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dollarstar
    New Member
    • Mar 2008
    • 8

    Querying dates of two fields.

    I'm not sure if I've disribed this right but this is what I need:

    I have two fields with dates in.

    I need some code that will look at the two dates and if the dates are more than four days apart then a warning message of some type with display saying that its been four or more days.

    I have my database made, and I've made a form for viewing and inputing the records.

    I've looked around everywhere to see if I can find an answer but as I'm not very experianced with Access I've come looking here requesting for help.

    Any help will will be greatly appreciated.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Code:
    If Not IsNull(Me.FirstDate) and Not IsNull(Me.SecondDate) Then
      If DateDiff("d", Me.FirstDate, Me.SecondDate) > 4 Then
    	MsgBox "It's been more than 4 days !"
      End If
    End If
    You don't say when you want this message to popup. If you want it to popup after entering one of these dates, place it in the AfterUpDate event for the textbox. If you want it to popup when moving to a record, place it in the Form_Current event.

    Welcome to TheScripts!

    Linq ;0)>

    Comment

    • Dollarstar
      New Member
      • Mar 2008
      • 8

      #3
      Originally posted by missinglinq
      Code:
      If Not IsNull(Me.FirstDate) and Not IsNull(Me.SecondDate) Then
        If DateDiff("d", Me.FirstDate, Me.SecondDate) > 4 Then
      	MsgBox "It's been more than 4 days !"
        End If
      End If
      You don't say when you want this message to popup. If you want it to popup after entering one of these dates, place it in the AfterUpDate event for the textbox. If you want it to popup when moving to a record, place it in the Form_Current event.

      Welcome to TheScripts!

      Linq ;0)>
      Hey, Thanks for the bit of code. I'm still having problems and feeling abit like an idiot at the moment.

      This is what I have got at the moment:

      Private Sub Site_Survey_Dat e_A(Form_Curren t)

      If Not IsNull(Me.Site_ Survey_Date_A) And Not IsNull(Me.G_A_C ompletion_Date_ A) Then
      If DateDiff("d", Me.Site_Survey_ Date_A, Me.G_A_Completi on_Date_A) > 4 Then
      MsgBox "It's been more than 4 days !"
      End If

      End If

      End Sub

      Which probably is totally wrong, but I'm getting nothing, and I haven't a clue what I'm doing really. Should the code go into section for the actual field or for the general form or what? I'm sorry but as I said before I'm kinda clueless.

      I think I have explained it wrong also. I believe what I need instead of what I originally described is:

      If there hasn't been a date inputted in since the date inputted in the other field then it should warn me.

      I've only just realised what I've said. Sorry about that.

      Comment

      • Dollarstar
        New Member
        • Mar 2008
        • 8

        #4
        Right, after much confusion this is what I basically need

        If DateRecieved is not null and SiteSurvey is Null

        Then

        If Date difference "DateReciev ed" and "TodaysDate " day is More than 4 different

        Then

        MessageBox "Site Survey field not completed after Four days!"

        End


        I know this isnt VB or Access code, its just basically what I need to be code. Any help would be greatly appreciated, I've been messing around most of the day and still gotten no where. Also I dont know what sub to put the code in, whether its the form or the actual SiteSurvey box

        Comment

        • Dollarstar
          New Member
          • Mar 2008
          • 8

          #5
          I DID IT!!

          Thanks for the previous code, it helped alot!

          Here is the code did what I wanted it to do:
          1. Private Sub Form_Current()

            If Not IsNull(Me.DateR ecieved) And IsNull(Me.SiteS urvey) Then

            If DateDiff("d", Me.DateRecieved , Me.TodayDate) > 4 Then
            MsgBox "Warninig Site Survey Date hasn't been completed after four days!"

            End If
            End If

            If Not IsNull(Me.SiteS urvey) And IsNull(Me.GACom pletion) Then

            If DateDiff("d", Me.SiteSurvey, Me.TodayDate) > 4 Then
            MsgBox "Warninig G.A. Completion Date hasn't been completed after four days!"

            End If
            End If

            End Sub


          Thanks again!

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            Glad you figured out what you actually needed and got it working!

            Linq ;0)>

            Comment

            Working...