Number of days calculation

Rockape

Registered User.
Local time
Today, 22:04
Joined
Aug 24, 2007
Messages
271
I wonder someone would help..

I have a form where I enter two dates i.e. a commence day and a final day and I also have a save button.

I would either
a. have a control on the save button which pops up a message if the final day is greater than the commence day and so preventing the save record

b. Or if the final day is entered and is recognised as a date before the commence day then to pop a message saying so and preventing the save record

Thanks
 
THis may not give you the whole solution but maybe it'll point you in the rigt direction?
Assuming your controls are txtCommenceDay and txtFinalDay:

Code:
Private Sub txtFinalDay_AfterUpdate()
 
    If Not IsNull(Me.txtFinalDay) And Me.txtFinalDay< Me.txtCommenceDay Then
        MsgBox "Final Date cannot be BEFORE the Start date!", , "Invalid Dates Entered"
        Me.txtFinalDay.SetFocus
    End If
 
I would put CazB code in the button click and Exit the procedure if the dates are invalid.
Code:
Private Sub [COLOR=Blue][B]yourButtonName[/B][/COLOR]_Click()
    If Not IsNull(Me.txtFinalDay) And Me.txtFinalDay< Me.txtCommenceDay Then
        MsgBox "Final Date cannot be BEFORE the Start date!", , "Invalid Dates Entered"
        Me.txtFinalDay.SetFocus
        [COLOR=Red][B]Exit Sub[/B][/COLOR]
    End If
    
    [COLOR=Green]'Keep Calm and Carry on Coding ![/COLOR]
[COLOR=Blue]End Sub
[/COLOR]
 
THis may not give you the whole solution but maybe it'll point you in the rigt direction?
Assuming your controls are txtCommenceDay and txtFinalDay:

Code:
Private Sub txtFinalDay_AfterUpdate()
 
    If Not IsNull(Me.txtFinalDay) And Me.txtFinalDay< Me.txtCommenceDay Then
        MsgBox "Final Date cannot be BEFORE the Start date!", , "Invalid Dates Entered"
        Me.txtFinalDay.SetFocus
    End If

Thanks I adapted it and it worked... :)
 
THis may not give you the whole solution but maybe it'll point you in the rigt direction?
Assuming your controls are txtCommenceDay and txtFinalDay:

Code:
Private Sub txtFinalDay_AfterUpdate()
 
    If Not IsNull(Me.txtFinalDay) And Me.txtFinalDay< Me.txtCommenceDay Then
        MsgBox "Final Date cannot be BEFORE the Start date!", , "Invalid Dates Entered"
        Me.txtFinalDay.SetFocus
    End If

Thanks very much.... it worked a treat
 
I would put CazB code in the button click and Exit the procedure if the dates are invalid.
Code:
Private Sub [COLOR=blue][B]yourButtonName[/B][/COLOR]_Click()
    If Not IsNull(Me.txtFinalDay) And Me.txtFinalDay< Me.txtCommenceDay Then
        MsgBox "Final Date cannot be BEFORE the Start date!", , "Invalid Dates Entered"
        Me.txtFinalDay.SetFocus
        [COLOR=red][B]Exit Sub[/B][/COLOR]
    End If
 
    [COLOR=green]'Keep Calm and Carry on Coding ![/COLOR]
[COLOR=blue]End Sub[/COLOR]

That was going to be my next suggestion, if the first bit worked ;)
 

Users who are viewing this thread

Back
Top Bottom