Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / December 2003

Tip: Looking for answers? Try searching our database.

Help please - cancelling an Item_Write Event from VB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AndyK - 29 Dec 2003 00:06 GMT
hi - I must be doing something really DUMB here - but what?

I'm tryng to validate and if invalid, cancel user changes to an Outlook Item from my VB app.  I've queried this newsgroup and the advice is use code lik

Function Item Write(
   If [invalid test] the
        Item_Write = Fals
   End I
End Functio

My code looks like this

Private Sub Item_Write(Cancel As Boolean
   If DateValue(Item.Start) <> DateValue(Item.End) The
       Item_Write = Fals
       ..
   End I
   ...
End Su

However when I try that I get a compile error from VB "Argument not optional" - help please?

thanks in advance
AndyK - 29 Dec 2003 15:16 GMT
btw I have also tried the following which compiles OK but doesn't cancel the Write

    Private Sub Item_Write(Cancel As Boolean)
        If DateValue(Item.Start) <> DateValue(Item.End) Then
            Cancel = True
            ...
        End If
        ....
    End Sub

   
    ----- AndyK wrote: -----
   
    hi - I must be doing something really DUMB here - but what??
   
    I'm tryng to validate and if invalid, cancel user changes to an Outlook Item from my VB app.  I've queried this newsgroup and the advice is use code like
   
    Function Item Write()
        If [invalid test] then
             Item_Write = False
        End If
    End Function
   
    My code looks like this:
   
    Private Sub Item_Write(Cancel As Boolean)
        If DateValue(Item.Start) <> DateValue(Item.End) Then
            Item_Write = False
            ...
        End If
        ....
    End Sub
   
    However when I try that I get a compile error from VB "Argument not optional" - help please??
   
    thanks in advance
Sue Mosher [MVP] - 29 Dec 2003 17:24 GMT
How are you instantiating Item in your VB code? It needs to be declared
WithEvents and then instantiated somewhere.

FWIW, I usually use DateDiff to compare dates.
Signature

Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> hi - I must be doing something really DUMB here - but what??
>
> I'm tryng to validate and if invalid, cancel user changes to an Outlook Item from my VB app.  I've queried this newsgroup and the advice is use code
like

> Function Item Write()
>     If [invalid test] then
[quoted text clipped - 15 lines]
>
> thanks in advance
AndyK - 29 Dec 2003 22:11 GMT
hi - thanks for replying & thanks for the DateDiff tip

Item is declared WithEvents and instantiated in code which responds to Explorer_SelectionChange.  I now have the thing working *most of the time* by setting Cancel = True rather than Item_Write = False.  I have posted again a few up from this one - this describes a Drag and Drop problem which still remains

Also while the "Cancel = True" works for one piece of validation which checks that the date of appointment is valid, it fails to undo the change when an appointment is changed to run over more than one day..

I'm thinking of changing the whole approach to use Items_ItemChange(), rather than Explorer_SelectionChange and Item_Write(), and using custom VB objects to store the key info I need from the pre-edited versions of the Appointments so I can change them back "manually" if the validation fails

thanks for any pointers

    ----- Sue Mosher [MVP] wrote: ----
   
    How are you instantiating Item in your VB code? It needs to be declare
    WithEvents and then instantiated somewhere
   
    FWIW, I usually use DateDiff to compare dates
    --
    Sue Mosher, Outlook MV
    Outlook and Exchange solutions at http://www.slipstick.co
    Author o
         Microsoft Outlook Programming - Jumpstart fo
         Administrators, Power Users, and Developer
         http://www.outlookcode.com/jumpstart.asp
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.