R
Rinze Smit
Hi,
I'm trying to create a macro, wich deletes a line, if a formfield is kept
empty.
So I wrote this macro, which starts up when the formfield is exited.
Whenever I use the formfieldname, the macro works fine. However when I
adress to the formfield, using the name, stored into a variable, I get the
5941 error.
What am I doing wrong?
Here's the first part of the code I use. The error occurs on line "If
ActiveDocument.FormFields(FrmfldName).Result = "" Then "
===============
Sub huidige_alinea_verwijderen()
'
' Macro opgenomen en aangepast op 10/20/2004 door Rinze Smit
'
Dim strMelding As String
Dim StrTitel As String
Dim FrmfldName As String
'Beveiliging verwijderen
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
End If
'controleren of het huidige formulierveld leeg is
'If Selection.FormFields.Count = 1 Then
'No textbox but a check- or listbox
' FrmfldName = Selection.FormFields(1).Name
' ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0
Then
FrmfldName = Selection.Bookmarks(Selection.Bookmarks.Count).Name
'End If
If ActiveDocument.FormFields(FrmfldName).Result = "" Then
MsgBox "Field is empty"
'Variabelen vullen mbt de melding
strMelding = "U heeft dit veld leeg gelaten. Wilt u deze regel
verwijderen?"
StrTitel = "Regel verwijderen!"
==================
Many thanks,
Rinze Smit
P.S. also posted in microsoft.public.word.vba. But that group doesn't seem
to be visited much.
I'm trying to create a macro, wich deletes a line, if a formfield is kept
empty.
So I wrote this macro, which starts up when the formfield is exited.
Whenever I use the formfieldname, the macro works fine. However when I
adress to the formfield, using the name, stored into a variable, I get the
5941 error.
What am I doing wrong?
Here's the first part of the code I use. The error occurs on line "If
ActiveDocument.FormFields(FrmfldName).Result = "" Then "
===============
Sub huidige_alinea_verwijderen()
'
' Macro opgenomen en aangepast op 10/20/2004 door Rinze Smit
'
Dim strMelding As String
Dim StrTitel As String
Dim FrmfldName As String
'Beveiliging verwijderen
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
End If
'controleren of het huidige formulierveld leeg is
'If Selection.FormFields.Count = 1 Then
'No textbox but a check- or listbox
' FrmfldName = Selection.FormFields(1).Name
' ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0
Then
FrmfldName = Selection.Bookmarks(Selection.Bookmarks.Count).Name
'End If
If ActiveDocument.FormFields(FrmfldName).Result = "" Then
MsgBox "Field is empty"
'Variabelen vullen mbt de melding
strMelding = "U heeft dit veld leeg gelaten. Wilt u deze regel
verwijderen?"
StrTitel = "Regel verwijderen!"
==================
Many thanks,
Rinze Smit
P.S. also posted in microsoft.public.word.vba. But that group doesn't seem
to be visited much.