B
Bob S
Hello-
I'm working w/Outlook 2000 and Outlook 2003. OSs are
Windows 2000 & XP respectively. I've created a custom
Task form with a custom page called "Task Details." This
page has an auto-numbering text box, formatted as
follows: the 2-digit year, a dash and then then a 4 digit
number (ex. 04-0001 for the first task). To get the auto
numbering to work, I've used the following code:
olFolderRegistry = 3
olFoldertasks = 13
myFormName = "XP Tasker" 'The name of the task form
Sub Item_Open()
' Set the Outlook NameSpace.
Set olns = Application.GetNameSpace("MAPI")
' Set the folder to the Contacts folder
Set myFolder = olns.GetDefaultFolder(olFolderTasks)
' #1/1/4501# is the internal representation of an
' empty data value in Outlook.
If Item.LastModificationTime = #1/1/4501# Then
' Item is a brand new item.
dim formpage 'As page
Set FormPage = Item.GetInspector.ModifiedFormPages("Task
Details")
Set control = formpage.controls("TxtAutonmbr")
'The control for the autonumbering
If control.text= cstr(right(date(),2))& "-9999" then
'I don't want more than 4 digits following "04-" so,
'if I hit 9999 I want to set it back to 0001 again
control.text = cstr(right(date(),2))&"-"&"0001"
Else
' Increment the number in the field.
control.text=cstr(cint(mid(control.text,4,len
(control.text)-3)))
'Get the last 4 digits
Control.text=CStr(CInt(control.text) + 1)
'add 1 & then fill in the zeros as necessary to make it
'4 digits in length
If len(control.text)= 1 then
control.text= "000" & control.text
end if
If len(control.text)= 2 then
control.text= "00" & control.text
end if
If len(control.text)= 3 then
control.text= "0" & control.text
end if
control.text= cstr(right(date(),2))& "-" & control.text
'add the 2 digit year & "-" to the front of the number
End If
'Now publish the form
Set myForm = Item.FormDescription myForm.Name= _
myFormName
myForm.PublishForm olFolderRegistry, myFolder
End If
End Sub
However, I also have command buttons on this form. And
once I've run this code, the command buttons will only
work when the form is first run. If I save and close the
form, then re-open the task, the command buttons stop
working.
If I remove the autonumbering/autoform-publish code and
publish the form "manually," the command buttons work
fine (but, of course, I lose the autonumber feature).
The autonumber/autoform-publish code seems to disable the
command buttons after the form is saved and closed.
Did I mess up the code for publishing this form? Any
help would be greatly appreciated.
The code for the command button is below. It opens Word,
puts data into a word document at selected bookmarks,
prints the doc and exits without saving. It works fine
when published "manually" as the only text in the
VBscript editor.
Thanks for taking the time to read this message, any help
would be appreciated.
Bob
Code for command button
Sub CMDOpenWD_Click
Dim objWord 'As Word.Application
Dim objDoc 'As Word.Document
Dim objSelect 'As Word.Selection
Dim objDocItem 'As DocumentItem
Dim control'As outlook control
Dim control2'As outlook control
Dim Control3'As outlook control
Dim ctlSubject'As outlook control subject Dim
formpage 'As page
Set FormPage = Item.GetInspector.ModifiedFormPages("Task
Details")
Set control = formpage.controls("textbox6")
Set control2 = formpage.controls("textbox7")
Set control3 = formpage.controls("textbox2")
Set objWord = CreateObject("Word.Application")
ctlSubject = item.subject
Set objDoc = objWord.Documents.open("d:\XP Cover
sheet1.doc" )
Set objSelect = objWord.Selection
objdoc.bookmarks("b1").select
objSelect.TypeText control.text
objdoc.bookmarks("b2").select
objSelect.TypeText control2.text
objdoc.bookmarks("b3").select
objSelect.TypeText control3.text
objdoc.bookmarks("b4").select
objSelect.TypeText ctlsubject
'objword.visible = true
objdoc.application.printout Msgbox "File printing"
Const wdDoNotSaveChanges = 0
objdoc.close wdDoNotSaveChanges
Set objdoc = nothing
objword.quit
Set objWord = Nothing
End Sub
I'm working w/Outlook 2000 and Outlook 2003. OSs are
Windows 2000 & XP respectively. I've created a custom
Task form with a custom page called "Task Details." This
page has an auto-numbering text box, formatted as
follows: the 2-digit year, a dash and then then a 4 digit
number (ex. 04-0001 for the first task). To get the auto
numbering to work, I've used the following code:
olFolderRegistry = 3
olFoldertasks = 13
myFormName = "XP Tasker" 'The name of the task form
Sub Item_Open()
' Set the Outlook NameSpace.
Set olns = Application.GetNameSpace("MAPI")
' Set the folder to the Contacts folder
Set myFolder = olns.GetDefaultFolder(olFolderTasks)
' #1/1/4501# is the internal representation of an
' empty data value in Outlook.
If Item.LastModificationTime = #1/1/4501# Then
' Item is a brand new item.
dim formpage 'As page
Set FormPage = Item.GetInspector.ModifiedFormPages("Task
Details")
Set control = formpage.controls("TxtAutonmbr")
'The control for the autonumbering
If control.text= cstr(right(date(),2))& "-9999" then
'I don't want more than 4 digits following "04-" so,
'if I hit 9999 I want to set it back to 0001 again
control.text = cstr(right(date(),2))&"-"&"0001"
Else
' Increment the number in the field.
control.text=cstr(cint(mid(control.text,4,len
(control.text)-3)))
'Get the last 4 digits
Control.text=CStr(CInt(control.text) + 1)
'add 1 & then fill in the zeros as necessary to make it
'4 digits in length
If len(control.text)= 1 then
control.text= "000" & control.text
end if
If len(control.text)= 2 then
control.text= "00" & control.text
end if
If len(control.text)= 3 then
control.text= "0" & control.text
end if
control.text= cstr(right(date(),2))& "-" & control.text
'add the 2 digit year & "-" to the front of the number
End If
'Now publish the form
Set myForm = Item.FormDescription myForm.Name= _
myFormName
myForm.PublishForm olFolderRegistry, myFolder
End If
End Sub
However, I also have command buttons on this form. And
once I've run this code, the command buttons will only
work when the form is first run. If I save and close the
form, then re-open the task, the command buttons stop
working.
If I remove the autonumbering/autoform-publish code and
publish the form "manually," the command buttons work
fine (but, of course, I lose the autonumber feature).
The autonumber/autoform-publish code seems to disable the
command buttons after the form is saved and closed.
Did I mess up the code for publishing this form? Any
help would be greatly appreciated.
The code for the command button is below. It opens Word,
puts data into a word document at selected bookmarks,
prints the doc and exits without saving. It works fine
when published "manually" as the only text in the
VBscript editor.
Thanks for taking the time to read this message, any help
would be appreciated.
Bob
Code for command button
Sub CMDOpenWD_Click
Dim objWord 'As Word.Application
Dim objDoc 'As Word.Document
Dim objSelect 'As Word.Selection
Dim objDocItem 'As DocumentItem
Dim control'As outlook control
Dim control2'As outlook control
Dim Control3'As outlook control
Dim ctlSubject'As outlook control subject Dim
formpage 'As page
Set FormPage = Item.GetInspector.ModifiedFormPages("Task
Details")
Set control = formpage.controls("textbox6")
Set control2 = formpage.controls("textbox7")
Set control3 = formpage.controls("textbox2")
Set objWord = CreateObject("Word.Application")
ctlSubject = item.subject
Set objDoc = objWord.Documents.open("d:\XP Cover
sheet1.doc" )
Set objSelect = objWord.Selection
objdoc.bookmarks("b1").select
objSelect.TypeText control.text
objdoc.bookmarks("b2").select
objSelect.TypeText control2.text
objdoc.bookmarks("b3").select
objSelect.TypeText control3.text
objdoc.bookmarks("b4").select
objSelect.TypeText ctlsubject
'objword.visible = true
objdoc.application.printout Msgbox "File printing"
Const wdDoNotSaveChanges = 0
objdoc.close wdDoNotSaveChanges
Set objdoc = nothing
objword.quit
Set objWord = Nothing
End Sub