Help please - cancelling an Item_Write Event from VB

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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.
--
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


AndyK said:
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
 
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
 
Back
Top