PDA

View Full Version : Solved: Where to put macros in dot?



Tommy
03-13-2006, 03:18 PM
Hi everyone,:hi:

Having a bit of a brain cramp today (not unusual). I was setting up a dot to use as a simple invoice. In the dot I placed 2 form fields, in the document_new event I placed some code. I want this code to fire only when the doc is started for the first time. (back to the code) I fill them like


ActiveDocument.Formfield("Text1").Result = Format(Now,"mmm dd, yyyy")
ActiveDocument.Formfield("Text3").Result = InputBox ("Enter invoice number").


All is well and good so far, that is untill I try to use it. :bug: I get the input box, I fill in the information just like I want it and wala no joy! For something so quick and easy I figured no brainer right. I wasted an hour and a half fighting with it and said well I can fake it by putting the code in the open event and checking if the formfield has a value. So instead I ask a question, cause I am just not getting something here and I don't like it :rofl:
Oh the code above is as best as I can remember it, I am sure I used ThisDocument and ActiveDocument, it wouldn't fill it in otherwise LOL maybe.

mdmackillop
03-13-2006, 03:49 PM
Hi Tommy
Note the "s" in FormFields
Regards
Malcolm

Private Sub Document_New()
ActiveDocument.Protect wdAllowOnlyFormFields
ActiveDocument.FormFields("Text1").Result = Format(Now(), "mmm dd, yyyy")
ActiveDocument.FormFields("Text3").Result = InputBox("Enter invoice number")
End Sub

lucas
03-13-2006, 05:55 PM
I'm glad I'm not the only one to make those kind of headaches for myself.
Love the grumpy draftsman avatar Tommy.

Tommy
03-13-2006, 06:39 PM
k no go still no joy :(

me thinks it could be the forms are not protectected or don't clear on .. anyway I think I will try bookmarks, this will not get the best of me :banghead: I will get it to work the way I want even if I have to change what I want :devil2:
so the actual code in question is (drum roll please):

in the ThisDocument code pane

Private Sub Document_New()
FillNum
End Sub
in a bas module

Public Sub FillNum()
ThisDocument.FormFields("Text1").Result = MonthName(Month(Now)) & " " & Day(Now) & ", " & Year(Now)
ThisDocument.FormFields("Text3").Result = InputBox("Enter Invoice Number", "Number")
End Sub



Steve still kinda rough on "grumpy draftsman", but funny huh :)

lucas
03-13-2006, 07:09 PM
Hey Tommy it worked for me.....
attached doc. just rename it .dot
let me know

fumei
03-13-2006, 09:31 PM
ThisDocument.FormFields("Text1").

should be ActiveDocument.FormFields.....

Tommy
03-14-2006, 07:19 AM
Hi Gerry,
I tried that also still no joy. It works just fine both ways if I step through the subs. I am using 2003 by the way.
I could be wrong but since I don't have the forms protected, would, in the doc new event, even if the formfields were filled by the code would they reset after the new event fires? Just a guess. Should I use bookmarks instead?

Tommy
03-14-2006, 08:01 AM
I added

ActiveDocument.Protect wdAllowOnlyFormFields

It works in 2000 I remove the above statement and it still works in 2000. I will not have time to look at the Protect till tonight.

Thank You for your interset and help so far

mdmackillop
03-14-2006, 10:54 AM
Hi Tommy,
Refer to Post #2.
Regards
Malcolm

Tommy
03-14-2006, 07:07 PM
See this is what happens when you get frustrated. :banghead: You swear up and down you tried that :thumb and yes ladies and gentlemen it was :devil2: ActiveDocument. So once again <sigh> brain cramp </sigh>. I apologize for wasting you time and thank you for helping me.:friends: I need to learn how to document what I have tried and what I haven't :whip