[AccessD] Resume command problem

Gustav Brock Gustav at cactus.dk
Tue Sep 25 09:09:20 CDT 2007


Hi Chester

You may try to replace CDate() with CVDate().

/gustav

>>> Chester_Kaup at kindermorgan.com 25-09-2007 15:52 >>>
Thanks everyone for your coding ideas. It almost works. The problem is
this. If the user does not enter a date it loops through the null error
check just fine. However when the user enters a valid date it displays
the message that the start date is after the end date when it is not. A
check of the code reveals that after a null check the next time a date
is entered the code thinks the date is text (puts quotes around it). I
tried a cdate on the start date but of course that doesn't work if it is
null. Ideas?

-----Original Message-----
From: accessd-bounces at databaseadvisors.com 
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gmail
Sent: Friday, September 21, 2007 2:20 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Resume command problem


I would change your code to:

Private Sub StartDate_Exit(Cancel As Integer)
    If Forms![frm Manifold Chart]!StartDate > Forms![frm Manifold
Chart]!EndDate Then
      MsgBox "Invalid Date. Start date must be before end date"
	cancel = true
    End If
End Sub

Also if "frm Manifold Chart" is your current form where this code exists
(and I suspect it is) then change it to

Private Sub StartDate_Exit(Cancel As Integer)
    If Me!StartDate > Me!EndDate Then
     MsgBox "Invalid Date. Start date must be before end date"
	cancel = true
    End If
End Sub

But, presumably your user will enter the Startdate before the Enddate.
I
would put some code in the OnCurrent:

me!EndDate.enabled = not isnull(me!StartDate) 

HERE IS AN EXAMPLE of the whole thing:

Option Compare Database
Option Explicit

Private Sub Form_Current()
  Me!EndDate.Enabled = Not IsNull(Me!StartDate)
End Sub

Private Sub StartDate_Exit(Cancel As Integer)
  If Me!StartDate > Me!EndDate Then
    MsgBox "Invalid Date. Start date must be before end date"
    Cancel = True
  ElseIf IsNull(Me!StartDate) Then
    MsgBox "You must enter a start date"
    Cancel = True
  Else
    Me!EndDate.Enabled = True
    Me!EndDate.SetFocus
  End If
End Sub
Private Sub EndDate_Exit(Cancel As Integer)
  If Me!EndDate < Me!StartDate Then
    MsgBox "Your End Date cannot be before the Start Date"
    Cancel = True
  ElseIf IsNull(Me!EndDate) Then
    MsgBox "You must enter an End Date"
    Cancel = True
  End If
End Sub

Max





More information about the AccessD mailing list