How to return the new value entered into a control onchange?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tim F
    New Member
    • Aug 2010
    • 16

    #1

    How to return the new value entered into a control onchange?

    Hi all,

    I have a problem with a form that I'm developing at work and would love any assistance so I'm not wondering all night!

    I have 3 fields, dateA, dateB and dateC.

    dateA and dateB contain 2 separate dates. dateC is empty by default.

    The user is supposed to enter a date in dateC that falls between the dates in A and B. I have already written the script to compare a given date value with dateA and dateB to make sure it meets the requirements.

    I want the check to occur as soon as the user picks a date with the date picker, before they can tab to another cell etc (this is the last field on the form and if I wait, they might hang up on the customer they are talking to before they realise th date is invalid if I don't trigger it immediately)

    My problem is that I can't find how to get the value of the new value dateC so that I can compare it.

    I am using the following, triggered by the onchange property.

    dim earlydate as date
    dim latedate as date
    dim prefdate as date

    earlydate=me.da teA.value
    latedate=me.dat eB.value
    prefdate=me.dat eC.value

    This returns a runtime error - invalid use of null. So it is setting prefdate to the old value of the cell rather than the new value that the user entered to trigger the onchange event. Is there any way to get the new value rather than the old value, so I can dim the value and start to use it??

    Many thanks!
  • Tim F
    New Member
    • Aug 2010
    • 16

    #2
    I resolved this by adding an onchange event to DateC that just said me.DateC.setfoc us. That entered the new value and let me use an AfterUpdate event to trigger my actual code, using me.undo to cancel the entry in DateC if it didn't meet my parameters.

    So effectively as soon as a value is entered, the code was triggered to check whetehr that value was correct, before the user could leave the field.

    Comment

    Working...