Word 2007 ContentControlOnexit bug needs focus developer tab

P

PeterHS

L.s,

I Bookmarkt my contentcontrols and use the content with REF fields in my
document. It works fine (when you bookmark the right way). But a need to
manualy update fields.

Now I want the fields to update automaticly when I leave the contentcontrol
field. I found the contentControlOnexit trigger, looks nice simple macro to
update all fields when I leave the contentcontrol.

But there is a BIG BUG, when the focus isn't on the UI developer tab but on
the start tab, when you select the contentcontrol, the onexit is fired
entering the contentcontrol creating a loop and hangsup.

I found a solution on the net which go's to the developer tab when entering
the contentcontrol (using the onenter trigger), but I don't want tab changes
and the developer tab on for the users.

Also there may by some way to connect fields in XML but it looks verry
complicated (to go where no one has gone before).

Anyone have some nice and clean solution (maybe Microsoft can fix the bug)

Manny thanks

Peter
 
M

Mehrdad Mirreza

I developed a workaround. The event is still fired again and again, but at
least I can have the code to be run only once. Since the
ContentcontrolOnEnter event doesn't go in loop like the ContentControlOnExit
event, i use the OnEnter event for running my code and the OnExit event just
to store the object I just leaved:

Public lastCC As ContentControl

Private Sub Document_ContentControlOnEnter(ByVal ContentControl As
ContentControl)

Debug.Print ContentControl.Tag, ContentControl.ID, "entered"

<<my code here>>

End Sub

Private Sub Document_ContentControlOnExit(ByVal ContentControl As
ContentControl, Cancel As Boolean)

Debug.Print Time, ContentControl.Tag, ContentControl.ID
Set lastCC = ContentControl

End Sub

It is still a big bug and I hope Microsoft will soon fix it.
-Mehrdad
 
G

Greg Maxey

Mehrdad,

Yes that method certainly has value in certain circumstances, but it can be
contrary in applications where you want to validate a user input. Enter 5
CCs named "Name" "Whole Number" "SSN" "Pass Code" and "Phone Number" and
then run the code that follows. The problem is that a user can enter a
field and then decide to exit the field with the mouse. If this happens the
event doesn't until the user decides to enter another CC. That could be the
very next thing (ideal), or minutes later (a potential nuisance), or not at
all (a problem).

Bottom line is it is broke bad and needs fixing. It is really disappointing
that this cool new feature has been broke since inception and still broken
nearly three years later. When Microsoft will decide to fix it is your
guess as good as mine.



Option Explicit
Dim lastCC As ContentControl

Private Sub Document_ContentControlOnEnter(ByVal ContentControl As
ContentControl)
On Error Resume Next
Validate lastCC, False
End Sub

Private Sub Document_ContentControlOnExit(ByVal ContentControl As
ContentControl, Cancel As Boolean)
Set lastCC = ContentControl
End Sub

Private Sub Validate(ByVal CC As ContentControl, Cancel As Boolean)
Dim pStr As String
Dim bGate1 As Boolean, bGate2 As Boolean, bGate3 As Boolean
Dim bGate4 As Boolean, bGate5 As Boolean, bValid As Boolean
Dim i As Long
Dim oRng As Word.Range
pStr = CC.Range.Text
bValid = False
Select Case CC.Title
Case "Name"
If CC.ShowingPlaceholderText = True Or pStr = "" Then
MsgBox "This field cannot be left blank."
CC.Range.Select
End If
Case "Whole Number"
If CC.ShowingPlaceholderText = True Or Not IsNumeric(pStr) Then
MsgBox "" & pStr & "" & " is not a valid number. Try again."
CC.Range.Select
CC.Range.Text = ""
ElseIf Val(pStr) > 50 Or Val(pStr) < 1 Then
MsgBox "" & pStr & "" & " is not between 1 and 50. Try again."
CC.Range.Select
CC.Range.Text = ""
ElseIf Val(pStr) <> Int(Val(pStr)) Then
MsgBox "" & pStr & "" & " is not a whole number. Try again."
Cancel = True
CC.Range.Text = ""
End If
Case Is = "SSN"
If Not pStr Like "#########" And Not pStr Like "###-##-####" Then
CC.Range.Select
MsgBox "Please enter the SSN in ""###-##-####"" format."
CC.Range.Text = ""
ElseIf pStr Like "#########" Then
pStr = Left(pStr, 3) & "-" & Mid(pStr, 4, 2) & "-" & Right(pStr, 4)
CC.Range.Text = pStr
End If
Case Is = "Pass Code"
bGate1 = False
bGate2 = False
bGate3 = False
bGate4 = False
bGate5 = False
If Len(pStr) > 5 And Len(pStr) < 10 Then
bGate1 = True
For i = 1 To Len(pStr)
If Mid(pStr, i, 1) Like "#" Then bGate2 = True
If Mid(pStr, i, 1) Like "[A-Z]" Then bGate3 = True
If Mid(pStr, i, 1) Like "[a-z]" Then bGate4 = True
If Mid(pStr, i, 1) Like "[@$%&]" Then bGate5 = True
Next i
End If
bValid = bGate1 And bGate2 And bGate3 And bGate4 And bGate5
If Not bValid Then
CC.Range.Select
MsgBox "You did not enter a valid passcode. Try Again."
CC.Range.Text = ""
End If
Case Is = "Phone Number"
If (pStr Like "(###) ###-####") Then Exit Sub
If (pStr Like "##########") Then
pStr = "(" & Left(pStr, 3) & ") " & Mid(pStr, 4, 3) & "-" &
Right(pStr, 4)
CC.Range.Text = pStr
ElseIf (pStr Like "###-###-####") Then
pStr = "(" & Left(pStr, 3) & ") " & Right(pStr, 8)
CC.Range.Text = pStr
Exit Sub
ElseIf (pStr Like "### ### ####") Then
pStr = Replace(pStr, " ", "-")
pStr = "(" & Left(pStr, 3) & ") " & Right(pStr, 8)
CC.Range.Text = pStr
ElseIf (pStr Like "(###)###-####") Then
pStr = Left(pStr, 5) & " " & Right(pStr, 8)
CC.Range.Text = pStr
Else
CC.Range.Select
MsgBox "Invalid entry. Try again."
CC.Range.Text = ""
End If
Case Else
MsgBox CC.Title & " Exit event fired."
End Select
End Sub
 
M

Mehrdad Mirreza

as at May 2011 the bug seems to be fixed by the updates in the past.
L.s,

I Bookmarkt my contentcontrols and use the content with REF fields in my
document. It works fine (when you bookmark the right way). But a need to
manualy update fields.

Now I want the fields to update automaticly when I leave the contentcontrol
field. I found the contentControlOnexit trigger, looks nice simple macro to
update all fields when I leave the contentcontrol.

But there is a BIG BUG, when the focus isn't on the UI developer tab but on
the start tab, when you select the contentcontrol, the onexit is fired
entering the contentcontrol creating a loop and hangsup.

I found a solution on the net which go's to the developer tab when entering
the contentcontrol (using the onenter trigger), but I don't want tab changes
and the developer tab on for the users.

Also there may by some way to connect fields in XML but it looks verry
complicated (to go where no one has gone before).

Anyone have some nice and clean solution (maybe Microsoft can fix the bug)

Manny thanks

Peter
On Tuesday, December 02, 2008 12:38 PM Greg Maxey wrote:
I certainly second Peter's motion to fix this bug!!

PeterHS wrote:
On Thursday, December 25, 2008 9:41 AM Greg Maxey wrote:
Mehrdad,

Yes that method certainly has value in certain circumstances, but it can be
contrary in applications where you want to validate a user input. Enter 5
CCs named "Name" "Whole Number" "SSN" "Pass Code" and "Phone Number" and
then run the code that follows. The problem is that a user can enter a
field and then decide to exit the field with the mouse. If this happens the
event doesn't until the user decides to enter another CC. That could be the
very next thing (ideal), or minutes later (a potential nuisance), or not at
all (a problem).

Bottom line is it is broke bad and needs fixing. It is really disappointing
that this cool new feature has been broke since inception and still broken
nearly three years later. When Microsoft will decide to fix it is your
guess as good as mine.



Option Explicit
Dim lastCC As ContentControl

Private Sub Document_ContentControlOnEnter(ByVal ContentControl As
ContentControl)
On Error Resume Next
Validate lastCC, False
End Sub

Private Sub Document_ContentControlOnExit(ByVal ContentControl As
ContentControl, Cancel As Boolean)
Set lastCC = ContentControl
End Sub

Private Sub Validate(ByVal CC As ContentControl, Cancel As Boolean)
Dim pStr As String
Dim bGate1 As Boolean, bGate2 As Boolean, bGate3 As Boolean
Dim bGate4 As Boolean, bGate5 As Boolean, bValid As Boolean
Dim i As Long
Dim oRng As Word.Range
pStr = CC.Range.Text
bValid = False
Select Case CC.Title
Case "Name"
If CC.ShowingPlaceholderText = True Or pStr = "" Then
MsgBox "This field cannot be left blank."
CC.Range.Select
End If
Case "Whole Number"
If CC.ShowingPlaceholderText = True Or Not IsNumeric(pStr) Then
MsgBox "" & pStr & "" & " is not a valid number. Try again."
CC.Range.Select
CC.Range.Text = ""
ElseIf Val(pStr) > 50 Or Val(pStr) < 1 Then
MsgBox "" & pStr & "" & " is not between 1 and 50. Try again."
CC.Range.Select
CC.Range.Text = ""
ElseIf Val(pStr) <> Int(Val(pStr)) Then
MsgBox "" & pStr & "" & " is not a whole number. Try again."
Cancel = True
CC.Range.Text = ""
End If
Case Is = "SSN"
If Not pStr Like "#########" And Not pStr Like "###-##-####" Then
CC.Range.Select
MsgBox "Please enter the SSN in ""###-##-####"" format."
CC.Range.Text = ""
ElseIf pStr Like "#########" Then
pStr = Left(pStr, 3) & "-" & Mid(pStr, 4, 2) & "-" & Right(pStr, 4)
CC.Range.Text = pStr
End If
Case Is = "Pass Code"
bGate1 = False
bGate2 = False
bGate3 = False
bGate4 = False
bGate5 = False
If Len(pStr) > 5 And Len(pStr) < 10 Then
bGate1 = True
For i = 1 To Len(pStr)
If Mid(pStr, i, 1) Like "#" Then bGate2 = True
If Mid(pStr, i, 1) Like "[A-Z]" Then bGate3 = True
If Mid(pStr, i, 1) Like "[a-z]" Then bGate4 = True
If Mid(pStr, i, 1) Like "[@$%&]" Then bGate5 = True
Next i
End If
bValid = bGate1 And bGate2 And bGate3 And bGate4 And bGate5
If Not bValid Then
CC.Range.Select
MsgBox "You did not enter a valid passcode. Try Again."
CC.Range.Text = ""
End If
Case Is = "Phone Number"
If (pStr Like "(###) ###-####") Then Exit Sub
If (pStr Like "##########") Then
pStr = "(" & Left(pStr, 3) & ") " & Mid(pStr, 4, 3) & "-" &
Right(pStr, 4)
CC.Range.Text = pStr
ElseIf (pStr Like "###-###-####") Then
pStr = "(" & Left(pStr, 3) & ") " & Right(pStr, 8)
CC.Range.Text = pStr
Exit Sub
ElseIf (pStr Like "### ### ####") Then
pStr = Replace(pStr, " ", "-")
pStr = "(" & Left(pStr, 3) & ") " & Right(pStr, 8)
CC.Range.Text = pStr
ElseIf (pStr Like "(###)###-####") Then
pStr = Left(pStr, 5) & " " & Right(pStr, 8)
CC.Range.Text = pStr
Else
CC.Range.Select
MsgBox "Invalid entry. Try again."
CC.Range.Text = ""
End If
Case Else
MsgBox CC.Title & " Exit event fired."
End Select
End Sub



Mehrdad Mirreza wrote:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top