A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Custom form not saving when fields changed programatically



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 8th 08, 01:45 AM posted to microsoft.public.outlook.program_forms
karlman[_2_]
external usenet poster
 
Posts: 18
Default Custom form not saving when fields changed programatically

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?

Thanks
Karl
  #2  
Old January 10th 08, 04:41 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

Dirtying the Subject property should work.

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

Thanks
Karl

  #3  
Old January 10th 08, 07:07 PM posted to microsoft.public.outlook.program_forms
karlman[_2_]
external usenet poster
 
Posts: 18
Default Custom form not saving when fields changed programatically

On Jan 10, 7:41*am, "Sue Mosher [MVP-Outlook]"
wrote:
Dirtying the Subject property should work.

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


Thanks
Karl- Hide quoted text -


- Show quoted text -


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.

I am probably missing something simple here. Maybe a setting on the
form?

Thanks
Karl
  #4  
Old January 10th 08, 07:17 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

No settings are involved. Maybe it's time you showed some code and explained whether you're writing code behind the form or in some other environment.

--
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 ...
On Jan 10, 7:41 am, "Sue Mosher [MVP-Outlook]"
wrote:
Dirtying the Subject property should work.

"karlman" wrote in ...
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?


Thanks
Karl- Hide quoted text -


- Show quoted text -


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.

I am probably missing something simple here. Maybe a setting on the
form?

Thanks
Karl
  #5  
Old January 10th 08, 07:31 PM posted to microsoft.public.outlook.program_forms
karlman[_2_]
external usenet poster
 
Posts: 18
Default Custom form not saving when fields changed programatically

On Jan 10, 10:17*am, "Sue Mosher [MVP-Outlook]"
wrote:
No settings are involved. Maybe it's time you showed some code and explained whether you're writing code behind the form or in some other environment.

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

On Jan 10, 7:41 am, "Sue Mosher [MVP-Outlook]"





wrote:
Dirtying the Subject property should work.


"karlman" wrote in ...
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?


Thanks
Karl- Hide quoted text -


- Show quoted text -


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.

I am probably missing something simple here. Maybe a setting on the
form?

Thanks
Karl- Hide quoted text -

- Show quoted text -


I am just adding code behind the form. I do write the code in MS
Visual Studio so I get the nicer editor and IntelliSense but then I
just copy/paste in the the form's code window.

I used to always keep an audit trail in the Message field. It was
simple but since users needed to add things themselves it could be
changed. Methods of detecting tampering were crude. 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
  #6  
Old January 10th 08, 08: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
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
conditionnal formating lost after saving custom form [email protected] Outlook and VBA 1 November 6th 07 02:51 PM
Custom Actions and Form Fields dch3 Outlook - Using Forms 3 August 2nd 07 09:15 PM
Saving Contacts With A Custom Designed Form...??? steve Outlook - Using Contacts 8 June 15th 07 05:57 PM
Saving Contacts With A Custom Form steve Outlook - Using Forms 0 June 13th 07 09:16 PM
importing custom fields into a custom form susan lasalle Outlook - Using Contacts 1 January 16th 07 10:01 PM


All times are GMT +1. The time now is 12:59 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.