PDA

View Full Version : Documents based ontemplate runs VBA clickevent only once



jellewouters
04-26-2013, 12:05 AM
Hii all,

Probably a simple question. I searched everywhere but both me and my colleague cannot find the answer.

It's kinda simple. I have a document (Microsoft Office Word - using VBA). On that document, there is a checkbox. When you tick the checkbox, a couple of events in two different modules will be executed. When you untick the box, it should also run some events.

In a normal document this works fine. Once I save it as a template, it runs only once. If I create a document based on the template, and i tick the box, everything works fine. Once I untick the box, nothing happens. When I tick the box again, it doesn't work either.

If I'm directly working in the template, everything runs smoothly. I really don't know what is going wrong.
The ClickEvent:

Private Sub CheckBox12_Click()
'Action which pops up when checkbox IA is clicked (checkbox12)

'Check if user didn't activated reading layout
runagain:
If ActiveWindow.View.ReadingLayout = True Then
GoTo viewmode
'If not, execute first steps.
Else
'Check if program runned earlier
If ModinitialiseIA.earlierchk = False Then
' Check if value is changed to empty, then start modInitialiseIA.backtonromal
If CheckBox12.value = False Then
ModinitialiseIA.BacktoNormal
' If value is changed to checkt, start modInitialiseIA.SettoIA
Else
ModinitialiseIA.SettoIA
End If
End If
End If
'After changing document, set focus to first table, first cell
ActiveDocument.Tables(1).Cell(row:=1, Column:=3).Range.Select
Exit Sub

'If reading layout is activated, change it.
viewmode:
MsgBox modtexts.error2, vbExclamation, "Internal Audit"
ActiveWindow.View.Type = wdPrintView
GoTo runagain
End Sub


Thanks for your help,

Jelle

gmaxey
04-26-2013, 05:59 AM
Is your code in the "ThisDocument" module of the template project? The problem doesn't appear to be related at all to templete or document as the following should illustrate:

Private Sub CheckBox1_Click()
MsgBox CheckBox1.Value
End Sub


which works regardless if template is used or a document based on the template.