View Single Post
  #6  
Old January 10th 08, 07:55 PM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Custom form not saving when fields changed programatically

What are oPF and oSM? What is the value of Saved after you change HTMLBody?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"karlman" wrote in message ...
Is there a way to force a form as "dirty" so Outlook attempts to save
it if someone clicks the 'X'?


I am changing the HTMLBody and even a custom field but the if I click
the 'X' then the form closes without saving. If I change any field
using the GUI then it does ask to save if I press the 'X'.


I have code that tells me if the form is dirty. Should I add something
in the Item_Close event and force the save at that point?


I was attempting to use the Milage property to no effect. I tried the
subject and that did not work either. I even put the subject field on
the form and can watch it change but Outlook still thinks it is a
"clean" form.

Interestingly, if I dirty the subject field manually through the GUI
then the form becomes dirty. Form some reason changing a custom or
builtin property through code is not dirtying the form. Only if I do
it throught the GUI.


This time around I
decided to make the message field read only and then provide a textbox
and button for adding notes. When you type something in the textbox
and push the button it adds the text to the message. I am actually
inserting it into the top of an HTML table using the HTMLBody
property. It works fine other than not dirtying the form so if that is
the only change you make it does not want to save it. Of course, I can
flag that it was updated and force a save in the Item_Close event if
the Item_Write event has not fired yet. That works but that also means
that if someone presses the X button the form is saved and that does
not make sense.

Here is where I update the HTMLBody field (also Mileage and Subject)
Sub AddNote(sText)
' Check
If Trim(sText) = "" Then Exit Sub

' Check if first add
If Not bAddedNote Then
bAddedNote = True
Item.Mileage = Item.Mileage + 1
Item.Subject = Now
End If

' Get existing body
sHTML = Item.HTMLBody

' Search for end of header
iPos = InStr(sHTML, "/th/tr")

' Highlight so each users notes are grouped
sHL = ""
If Item.Mileage / 2 = Int(Item.Mileage / 2) Then sHL = ";background-
color: lightgoldenrodyellow"

' Insert new line
sHTML2 = Left(sHTML, iPos + 9)
sHTML2 = sHTML2 & "trtd style='width:100px" & sHL & "'" &
FormatDateTime(Now, 2) & " " & FormatDateTime(Now, 4) & "/td"
sHTML2 = sHTML2 & "td style='width:125px" & sHL & "'" &
oPF.CurrentUser & "/td"
sHTML2 = sHTML2 & "td style='" & sHL & "'" & sText & "/td/tr"
sHTML2 = sHTML2 & Mid(sHTML, iPos + 10)

' Update body
Item.HTMLBody = sHTML2

End Sub


Here is what I have so far in the Item_Write and Item_Close events:
' If readonly then do not save
If oPF.ReadOnly Then
Item_Write = False
Item.Close(1)
Exit Function
End If

' Save If New
If oPF.IsNew Then Item.Save

' Update user types
oSM.AddUserType "LP", oPF.Field("LPName")
oSM.AddUserType "LC", oPF.Field("LCName")
oSM.AddUserType "DEUW", oPF.Field("DEUWName")
oSM.AddUserType "Funder", oPF.Field("FunderName")
oSM.AddUserType "Treasury", oPF.Field("TreasuryName")

' Send emails
'If Ubound(oSM.GetEmailRecipients(oPF.Field("CurrentSt atus"))) -1
Then
'For Each sEmail In
oSM.GetEmailRecipients(oPF.Field("CurrentStatus"))
' If Trim(sEmail) "" Then
' oPF.SendEmail sEmail,
oSM.GetEmailText(oPF.Field("CurrentStatus")),"TEST "
' End If
'Next
'End If

' Update subject
oPF.CreatePFItem(oPF.Controls("txtLoanNumber").Val ue)

bWriteFired = True
End Function


Function Item_Close()
' Unlock
oPF.UnlockItem(False)

End Function
Ads