G
Guest
I have a form field (an invoice) with a CommandButton to run a macro wich inserts the incoice number from c:\settings.txt (and saves the new numer)
It´s great, but if I click it several times (to increase the invoice number) it adds the new number before the old, instead of clearing the bookmark and inserting the new number in an empty field.
Ie: If a press the button once, my bookmark says 033. But if I press it twice, is says 034033 instead of 034.
So I´d want a code for clearing the bookmarked field.
Here´s my code (the unprotect and protect is there because I run a form field)
Private Sub CommandButton1_Click()
ActiveDocument.Unprotect
Order = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
Thanks for your answer!
It´s great, but if I click it several times (to increase the invoice number) it adds the new number before the old, instead of clearing the bookmark and inserting the new number in an empty field.
Ie: If a press the button once, my bookmark says 033. But if I press it twice, is says 034033 instead of 034.
So I´d want a code for clearing the bookmarked field.
Here´s my code (the unprotect and protect is there because I run a form field)
Private Sub CommandButton1_Click()
ActiveDocument.Unprotect
Order = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "00#")
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
Thanks for your answer!