• Macro (Access 97)

    Author
    Topic
    #379648

    Here I am again – trying to do something that seems obvious but apparently not. On the After Update event of date field on a form I attached a macro. In the condition area I have [Bkcomdate] < [dateindept]. Then I have cancelEvent, MsgBox (which says Book Complete Date must be greater than Date in Department), and gotocontrol (bkcomdate). No matter what date I put in bkcomdate, that message appears. What condition should I put to make this happen. Thank you for your time and patience.

    Viewing 1 reply thread
    Author
    Replies
    • #632837

      Post your Macro to the list.

      Right mouse click on your macro

      Left mouse click on Save As/Export

      Select “Save as Visual Basic Module”

      Select Convert

      Click on the Modules Tab

      Copy and post the contents of the “Converted Macro- Your Macro Name”

    • #632840

      As implied by accdb, code is easier for us to help you with than macros. However, one this to keep in mind is that a null value always compares false against any other value. So, check [dateindept]. If it is null at the time you are entering the data into [bkcomdate], then you’ll get your validation message.

      If that’s the problem, either ensure that [bkcomdate] is not null, or use something like [dateindept] is null or [bkcomdate]<[dateindept]

      • #632847

        OK, how would I write code for the after update event of the field bkcomdate so that if that date is not greater than the dateindept a message appears stating that the book complete date must be greater than the date in department. I thought a macro would be easier for me to write than code.

        • #632860

          You need to use the BeforeUpdate event, for the AfterUpdate event can’t be canceled.

          Your code could lool like this:

          Private Sub txtBkComDate_BeforeUpdate(Cancel As Integer)
          If txtBkComDate < txtDateInDept Then
          MsgBox "BkComDate must be on or after DateInDept."
          Cancel = True
          End If
          End Sub

        • #636089

          Macros are possibly easier to write than VBA code, but you should get used to writing VBA code, it’s not hard after a while. Plus code has advantages over macros and you definitely have more control with VBA code.
          Pat smile

          • #636167

            Well-written macros are not much easier than VBA code and can be harder because you spend a lot of time beating your head against the limitations of macros.

    Viewing 1 reply thread
    Reply To: Macro (Access 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: