Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Posts
    8

    Unanswered: can I call a function from "Validation Rule"

    I'm trying to validate user input from a form.

    I have function that does validates user input and it's stored in a module. I call this function from the "Validation Rule" field of a text box. The function runs correctly (I tested w/ MsgBox statments in different places), but the Access error mesg that says validation rule is not met always pops up no matter what I enter. Can anyone tell me what I'm doing wrong?

  2. #2
    Join Date
    Sep 2003
    Location
    Caldes de Malavella, Spain
    Posts
    244
    You cannot call a function from a validation rule. You are getting the error message every time because your rule is not being interpreted as a function call.

    Instead, try calling your function from the text box's BeforeUpdate event.
    Andy Briggs
    Elmhurst Solutions Limited
    Database Development and Consultancy
    http://www.elmhurstsolutions.com

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    or the forms before update event
    .. in any event if the data is invalid remember to set the cancel flag (part of the "before update" event fnction definition to stop the update event occuring.

    In some cases it is arguable that you could place the validation in each controls "before update" event or the forms "before update" event.

    The only thing to watch out for is triggering actions which can cause lockouts or contentions. Such as placing 'setfocus' events or code on 'lost focus' / 'got focus' events
    HTH

  4. #4
    Join Date
    Oct 2004
    Posts
    8
    andybriggs, healdem. you guys are very helpful!!
    I did put my function in the BeforeUpdate event of box, but I didn't know how to set cancel flag so it won't update when input is invalid (exactly what healdem said).

    It is working fine now and you wouldn't believe what happened. Since the function is called and runs correctly when called from Validation Rule field, it just doesn't understand the returned value or never evaluates the returned value. I thought maybe I just need to make it a comparison, doesn't hurt to try, so I put "ValidateInput(var) = Ture", and IT WORKED!! I can't believe it.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    way to go di cheung
    lots of comments made on these threads are offered as assistance to achieve your aims. They are not a replacement for your own effort.

    Great you tried some code....
    it didn't work, you found a way round it. One of the strengths, and weaknessess, of VB/VBA is that there are often many possible solutions to a problem. Which is appropriate depends on your expertese.

Posting Permissions

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