#1   Report Post  
Posted to microsoft.public.word.docmanagement
Jason K. Jason K. is offline
external usenet poster
 
Posts: 5
Default calendar Object

I'm trying to use the calendar object in an online form I created. The code I
have was written by Martin Green
(http://www.fontstuff.com/word/wordtut03a.htm). It works great on the
computer I created the fields with (Word 03) but when I send the form to
another computer (Word 02) I get an error message that says "This method or
property is not available because the object refers to a protected area of
the document." If I unlock the form in Word 02 I can run the macro just fine.

The code looks like this (Form Code)
Private Sub Calendar1_Click()
' Transfer date selected on calendar to the insertion
' insertion and close UserForm.
Selection.Text = Format(Calendar1.Value, "m/d/yy")
Selection.MoveRight Unit:=wdCharacter, Count:=1
Unload Me
End Sub

Private Sub cmdClose_Click()
' Close the form without entering a date if the user
' presses the [ESCAPE] key
Unload Me
End Sub

Private Sub UserForm_Initialize()
' If selection is a date show the same date, otherwise show
' today's date.
If IsDate(Selection.Text) Then
Calendar1.Value = DateValue(Selection.Text)
Else
Calendar1.Value = Date
End If
End Sub


The code looks like this (This Document Code)
Sub OpenCalendar()
' Display the frmCalendar UserForm
frmCalendar.Show
End Sub

Private Sub Document_Close()
On Error Resume Next
CustomizationContext = NormalTemplate
' Cancel the keyboard shortcut "Ctrl+Shift+C"
KeyBindings.Key(KeyCode:=BuildKeyCode(wdKeyControl , _
wdKeyShift, wdKeyC)).Clear
' Remove the "Insert Date" command from the right-click menu
Application.CommandBars("Text").Controls("Insert Date").Delete
End Sub

Private Sub Document_Open()
Dim NewControl As CommandBarControl
' Assign the keyboard shortcut "Ctrl+Shift+C"
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, _
wdKeyShift, wdKeyC), KeyCategory:=wdKeyCategoryMacro, _
Command:="ThisDocument.OpenCalendar"
' Add the "Insert Date" command to the right-click menu
Set NewControl = Application.CommandBars("Text").Controls.Add
With NewControl
..Caption = "Insert Date"
..OnAction = "ThisDocument.OpenCalendar"
..BeginGroup = True
End With
End Sub

Martin's website says it should work on most versions of Word.
Maybe I need the form to unlock, launch the calendar object, and then
re-lock? Or, maybe there is another way? Something I'm missing?

If you have the time to take a look at this, I would be very appreciative.

Jason K.
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default calendar Object

Hi Jason,

The code you found isn't intended to be used in a protected form, but
to insert a date in regular text. The core of the problem is what the
code tries to do with the result of the calendar:

Selection.Text = Format(Calendar1.Value, "m/d/yy")

isn't allowed in a protected form, because it's interpreted as an
attempt to remove the form field. Instead, what you need is something
like this, but using the real name of the field that receives the
date:

ActiveDocument.FormFields("SomeDate").Result = _
Format(Calendar1.Value, "m/d/yy")

In fact, in a protected form you don't need a lot of the code here.
Instead of adding a macro's name as a command to the right-click menu,
assign the OpenCalendar macro as the Entry macro of the particular
form field that should contain the date. Get rid of the Document_Open
and Document_Close routines (which also are ill-advised because they
alter Normal.dot, generally a bad idea).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

On Fri, 29 Dec 2006 11:02:00 -0800, Jason K.
wrote:

I'm trying to use the calendar object in an online form I created. The code I
have was written by Martin Green
(http://www.fontstuff.com/word/wordtut03a.htm). It works great on the
computer I created the fields with (Word 03) but when I send the form to
another computer (Word 02) I get an error message that says "This method or
property is not available because the object refers to a protected area of
the document." If I unlock the form in Word 02 I can run the macro just fine.

The code looks like this (Form Code)
Private Sub Calendar1_Click()
' Transfer date selected on calendar to the insertion
' insertion and close UserForm.
Selection.Text = Format(Calendar1.Value, "m/d/yy")
Selection.MoveRight Unit:=wdCharacter, Count:=1
Unload Me
End Sub

Private Sub cmdClose_Click()
' Close the form without entering a date if the user
' presses the [ESCAPE] key
Unload Me
End Sub

Private Sub UserForm_Initialize()
' If selection is a date show the same date, otherwise show
' today's date.
If IsDate(Selection.Text) Then
Calendar1.Value = DateValue(Selection.Text)
Else
Calendar1.Value = Date
End If
End Sub


The code looks like this (This Document Code)
Sub OpenCalendar()
' Display the frmCalendar UserForm
frmCalendar.Show
End Sub

Private Sub Document_Close()
On Error Resume Next
CustomizationContext = NormalTemplate
' Cancel the keyboard shortcut "Ctrl+Shift+C"
KeyBindings.Key(KeyCode:=BuildKeyCode(wdKeyContro l, _
wdKeyShift, wdKeyC)).Clear
' Remove the "Insert Date" command from the right-click menu
Application.CommandBars("Text").Controls("Inser t Date").Delete
End Sub

Private Sub Document_Open()
Dim NewControl As CommandBarControl
' Assign the keyboard shortcut "Ctrl+Shift+C"
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, _
wdKeyShift, wdKeyC), KeyCategory:=wdKeyCategoryMacro, _
Command:="ThisDocument.OpenCalendar"
' Add the "Insert Date" command to the right-click menu
Set NewControl = Application.CommandBars("Text").Controls.Add
With NewControl
.Caption = "Insert Date"
.OnAction = "ThisDocument.OpenCalendar"
.BeginGroup = True
End With
End Sub

Martin's website says it should work on most versions of Word.
Maybe I need the form to unlock, launch the calendar object, and then
re-lock? Or, maybe there is another way? Something I'm missing?

If you have the time to take a look at this, I would be very appreciative.

Jason K.

  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Jason K. Jason K. is offline
external usenet poster
 
Posts: 5
Default calendar Object

These two changes, did the trick.

Dim ActiveField As String
ActiveField = Selection.Bookmarks(1).Name
ActiveDocument.FormFields(ActiveField).Result = _
Format(Calendar1.Value, "m/d/yy")

Dim ActiveField As String
Dim CurrentEntry As String
ActiveField = Selection.Bookmarks(1).Name
CurrentEntry = ActiveDocument.FormFields(ActiveField).Result

Thanks for your help!








================================================== ===

"Jay Freedman" wrote:

Hi Jason,

The code you found isn't intended to be used in a protected form, but
to insert a date in regular text. The core of the problem is what the
code tries to do with the result of the calendar:

Selection.Text = Format(Calendar1.Value, "m/d/yy")

isn't allowed in a protected form, because it's interpreted as an
attempt to remove the form field. Instead, what you need is something
like this, but using the real name of the field that receives the
date:

ActiveDocument.FormFields("SomeDate").Result = _
Format(Calendar1.Value, "m/d/yy")

In fact, in a protected form you don't need a lot of the code here.
Instead of adding a macro's name as a command to the right-click menu,
assign the OpenCalendar macro as the Entry macro of the particular
form field that should contain the date. Get rid of the Document_Open
and Document_Close routines (which also are ill-advised because they
alter Normal.dot, generally a bad idea).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

On Fri, 29 Dec 2006 11:02:00 -0800, Jason K.
wrote:

I'm trying to use the calendar object in an online form I created. The code I
have was written by Martin Green
(http://www.fontstuff.com/word/wordtut03a.htm). It works great on the
computer I created the fields with (Word 03) but when I send the form to
another computer (Word 02) I get an error message that says "This method or
property is not available because the object refers to a protected area of
the document." If I unlock the form in Word 02 I can run the macro just fine.

The code looks like this (Form Code)
Private Sub Calendar1_Click()
' Transfer date selected on calendar to the insertion
' insertion and close UserForm.
Selection.Text = Format(Calendar1.Value, "m/d/yy")
Selection.MoveRight Unit:=wdCharacter, Count:=1
Unload Me
End Sub

Private Sub cmdClose_Click()
' Close the form without entering a date if the user
' presses the [ESCAPE] key
Unload Me
End Sub

Private Sub UserForm_Initialize()
' If selection is a date show the same date, otherwise show
' today's date.
If IsDate(Selection.Text) Then
Calendar1.Value = DateValue(Selection.Text)
Else
Calendar1.Value = Date
End If
End Sub


The code looks like this (This Document Code)
Sub OpenCalendar()
' Display the frmCalendar UserForm
frmCalendar.Show
End Sub

Private Sub Document_Close()
On Error Resume Next
CustomizationContext = NormalTemplate
' Cancel the keyboard shortcut "Ctrl+Shift+C"
KeyBindings.Key(KeyCode:=BuildKeyCode(wdKeyContro l, _
wdKeyShift, wdKeyC)).Clear
' Remove the "Insert Date" command from the right-click menu
Application.CommandBars("Text").Controls("Inser t Date").Delete
End Sub

Private Sub Document_Open()
Dim NewControl As CommandBarControl
' Assign the keyboard shortcut "Ctrl+Shift+C"
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, _
wdKeyShift, wdKeyC), KeyCategory:=wdKeyCategoryMacro, _
Command:="ThisDocument.OpenCalendar"
' Add the "Insert Date" command to the right-click menu
Set NewControl = Application.CommandBars("Text").Controls.Add
With NewControl
.Caption = "Insert Date"
.OnAction = "ThisDocument.OpenCalendar"
.BeginGroup = True
End With
End Sub

Martin's website says it should work on most versions of Word.
Maybe I need the form to unlock, launch the calendar object, and then
re-lock? Or, maybe there is another way? Something I'm missing?

If you have the time to take a look at this, I would be very appreciative.

Jason K.


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
calendar control tikchye_oldLearner57 Microsoft Word Help 2 July 30th 06 02:15 AM
I used a 2006 Word Calendar Template last year, it was calendar wi PADutchman New Users 2 July 15th 06 02:52 AM
Calendar object Slow Learner Microsoft Word Help 0 September 10th 05 07:21 PM
Adding Border to an object moves the caption!?? bandy2000 Microsoft Word Help 1 March 27th 05 04:21 PM
MS Word Picture Object tj Microsoft Word Help 0 January 26th 05 03:09 AM


All times are GMT +1. The time now is 10:19 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"