Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code not cancelling all events. 1

Status
Not open for further replies.

aexley

Technical User
Jul 9, 2001
147
GB
When this pice of code determines that the user has entered a 'No' response it resets the 'Next Call Date' field to it's previous value. What it doesn't do is stop the action that the user took immediatley after changing the 'Next Call Date'. For example, the user can change the date then immediatley click on a button to exit the form. The code below stops the update of the field but not the exit. How do I do this?:

Private Sub NEXT_CALL_DATE_AfterUpdate()

If (Forms![Contact Information]![NEXT CALL DATE] > DateAdd("m", 6, Date)) Then

If (Eval("MsgBox(""You have entered a date that is greater than six months away. Is this correct?"",4,""Please confirm date."")=7")) Then
DoCmd.CancelEvent
DoCmd.GoToControl "NEXT CALL DATE"
Forms![Contact Information]![NEXT CALL DATE] = Forms![Contact Information]![NEXT CALL DATE].OldValue
Else
End If

If (Eval("[Forms]![Contact Information]![NEXT CALL DATE] Is Null")) Then
End If
Else
End If
End Sub

Many thanks in advance.

Quote for the day: "If that 'New!' washing powder is so good, does that mean the old one was rubbish?"
 
You're using the wrong event. It should be a before update event......

Craig
 
Thanks but with the code in the 'BeforeUpdate' event, it doesn't appear to run at all.
 
Wow! You have alot of extraneous code, friend.

I'm not sure why you're using all the extra Eval's. I took the liberty to chop down your code and re-write it for a BeforeUpdate event, as per Craig's suggestion, and tested it (duplicating your form and field name.) It works.

Here's what I came up with, and it works great.
Code:
Private Sub NEXT_CALL_DATE_BeforeUpdate(Cancel As Integer)
    If Not (IsDate(Me.NEXT_CALL_DATE)) Then
        Cancel = True
    ElseIf Me.NEXT_CALL_DATE.Value > DateAdd("m", 6, Date) Then
        If (MsgBox("You have entered a date that is greater than six months away." _
         & " Is this correct?", vbYesNo, "Please confirm date.") = 7) Then
            Cancel = True
        End If
    End If
End Sub

-MoGryph
[80)
 
Many thanks to you both. The rewrite is perfect.

I think its about time I invested in a developers handbook.

Thanks,

aexley
 
Handbooks are okay, but you'll learn over time either way. Just keep digging in the Microsoft Access Help, and the examples that it contains.

Another powerful source of information is the Object Browser. You'll find loads and loads of information (overwhelming at times) to satisfy your questions on how things work. What I did when I started learning Access, was to every once in awhile, poke my nose in the Object Browser, and just scroll down the list of objects. If I saw an object name in there that I didn't recognize, but looked interesting, I'd check it out. If there's anything in there I don't feel I completely understand, I check it out. It's a great tool...

And make sure to peek at the code in the Sample databases. Don't be afraid to pick them apart (just make a backup of it before you try to break things to see what they do.)They're really helpful, and they'll give you some insight to some more advanced code when you're ready for that too.


-MoGryph
[8O)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top