Results 1 to 4 of 4
  1. #1
    Join Date
    May 2008
    Posts
    48

    Unanswered: Before Update event - Update Date through Combo Box

    I am trying to put a condition in Before Updaate event but the same does not work.

    Private Sub Date_of_Production_BeforeUpdate(Cancel As Integer)
    If Me.Date_of_Production > Date Then
    MsgBox " The Date of Production must not come after the today's Date"
    Cancel = True
    Exit Sub
    End Sub
    End If

    Actually, I tried to pull date from a calender. In that it does not work and if I manually enter the date, it perfectly works. I have also tried to use the event through Lost_focus() that gives a message but save the chosen date.

    Please suggest me how to resolve this issue.

    Thanks in advance

  2. #2
    Join Date
    May 2008
    Posts
    48
    I am trying to put a condition in Before Updaate event but the same does not work.
    Opps! Error :
    End if
    End sub
    It should be read as

    Private Sub Date_of_Production_BeforeUpdate(Cancel As Integer)
    If Me.Date_of_Production > Date Then
    MsgBox " The Date of Production must not come after the today's Date"
    Cancel = True
    Exit Sub
    End If
    End Sub

    Actually, I tried to pull date from a calender. In that it does not work and if I manually enter the date, it perfectly works. I have also tried to use the event through Lost_focus() that gives a message but save the chosen date.

    Please suggest me how to resolve this issue.

    Thanks in advance

  3. #3
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Please provide full information about the code you use (what calendar control to you use, how do you call it, etc.) and also the error message and error code you receive while using it.

    As far as I can guess, this:
    Code:
    If Me.Date_of_Production > Date Then
    could be incorrect towards what is returned by the calendar control.
    Have a nice day!

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I might use the AfterUpdate event instead.

    Private Sub Date_of_Production_AfterUpdate()
    If Me!Date_of_Production > Date() Then
    MsgBox " The Date of Production must not come after the today's Date"
    Me!Date_of_Production = me.date_of_production.previousvalue (or = Null)
    Refresh
    End If
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •