Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 31

Thread: Templates verses Forms/Document

  1. #1
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location

    Question Templates verses Forms/Document

    I am sorry that my terminology is off.

    I have created a template ( why, I don't know). I want people to do the following

    1) open it.
    2)fill out the fields
    3) Press a command button, that will save it to a different location (after the form has been checked to see if all the required fields are completed)
    4) Close the original.
    5) not change the original.

    Please advise as to the best way about this. I am a VB programmer trying set up a word form.

    Cheers,
    Aaron
    Last edited by Merkava; 09-17-2006 at 01:32 AM.

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    A Word Template (a .dot file) is the correct 'tool'. Double clicking on a template then causes a new document based on the template (essentially a copy of the template) to be created and leaves the template itself unchanged.

    Do you have the Form set up or do you need any specific help with it?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location
    Hi Tony,

    I have made a form, but there are several problems:

    1) populating Comboboxes, my VB training says "use an array when the form loads you populate the combobox. This does not seem appropriate here. I'm not using a DB. My main goal is that there be little "intervention" from the user.

    2) When I save the form to a new location (without changing the template), I want to use VBA to use the NETSEND command to notify the appropriate person that they have a form to tend to.

    I think that these to "hurdles" are large enough for now.

    TIA

    Cheers,
    Aaron

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Aaron,

    There are two types of controls you can use in Word.

    If you want to have what is called a Word Form (I'm not sure it really has a proper name) which 'works' when the document is 'protected for Forms' you should use controls from the Forms Toolbar. This has a dropdown control but it is limited to a maximum of 25 entries.

    You can also use ActiveX controls from the Control Toolbox. These don't sit very well with Forms Controls, they are harder to control but, ultimately I suppose, more powerful.

    I would recommend the Forms controls for what I imagine you are doing. It doesn't have a command button but you can have code which traps the Save or SaveAs commands to do what you want. Create a macro called FileSave and/or one called FileSaveAs and they will run instead of the builtin commands when the menu options are chosen. Alternatively you could add your own toolbar - or your own button on an existing toolbar - to run the code you want to.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  5. #5
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location
    Is there anywhere I could see an example of what you are referring to? I am aware of the Form controls, but am even more at a loss how Read them from code and work with them.

    Cheers,
    Aaron

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    ActiveX comboboxes require code to populate them. Normally these would be done using the Document_Open event (although you certainly could use an other event), so the combobox is populated from the start. Something like:[vba]Private Sub Document_Open()
    ComboBox1.AddItem "First item"
    ComboBox1.AddItem "Second item"
    ComboBox1.AddItem "Third item"
    ComboBox1.ListIndex = 0
    End Sub[/vba]If an ActiveX combobox is not populated by code, it remains empty. Although there is an interesting aspect to this. Run the above code, not by opening the document, but by simply running the procedure. The items are placed into the combobox. Now, comment out the Document_Open procedure. The items are still in the combobox.

    Save the file, and open it - the Document_Open event is commented out, so the combobox is NOT populated. And this is true. There will be nothing in the list...EXCEPT the combobox WILL still show "First item" in it. You can drop down the list and it IS empty, but it will show "First item" in it. Apparently, the text of .ListIndex as a property persists, regardless of whether ListCount = 0. This seems strange to me. In any case, it is always a good idea when populating a combobox to use .Clear to explicitly empty it anyways.

    FormField comboboxes (actually called DropDown fields) are normally populated manually. That is, the FormField is selected, and with a right click selecting Properties. Each item is then entering into the list.

    FormFields can also be populated by code. [vba]Sub PopulateDropDown()
    With ActiveDocument.FormFields("Dropdown1").DropDown.ListEntries
    .Clear
    .Add "First item"
    .Add "Second item"
    .Add "Third item"
    ' etc
    End With
    End Sub[/vba]I am not quite following what you are doing. If you are using formfields, there is no intervention by the users. Just populate the formfield.

  7. #7
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location
    Hi,

    Here is what is supposed to happen, by the numbers:

    1) user opens the template/form
    2) user fills in form by choosing predetermined options from combo boxes, and filling in several text boxes.
    3) user presses a "Save" button, the required fields are then "checked" to see if they have been filled in.
    4) if everything is verified the form is save to a different location, a system command(Netsend) will notifiy the recepient,and the template is closed unchanged.
    5) if the required fields are not filled in there will be a message will apear to instruct user to complete the form and steps 4 and 5 will be repeated.

    I hope that this clarifies what I am trying to do.

    Cheers,
    Aaron

  8. #8
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location
    Hi,

    Here is the code that I am using
    [vba]
    Private Sub cmdFinancial_Click()
    ActiveDocument.SaveAs "u:\Miscellaneous\Escalations\Callbacks - SV review\Financial\test.doc", wdFormatText
    Shell ("c:\windows\system32\net.exe send alonb ""Alon, a new Financial escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send badery ""Bader, a new Financial escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send garyn ""Gary a new Financial escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send yaacovp ""Jacob, a new Financial escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send martynf ""Martyn, a new Financial escalation has arrived.""")
    ActiveDocument.Close
    End Sub

    Private Sub cmdSpiral_Click()
    ActiveDocument.SaveAs "u:\Miscellaneous\Escalations\Callbacks - SV review\Spiral\test.doc", wdFormatText
    Shell ("c:\windows\system32\net.exe send alonb ""Alon, a new Spiral escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send badery ""Bader, a new Spiral escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send garyn ""Gary a new Spiral escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send yaacovp ""Jacob, a new Spiral escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send martynf ""Martyn, a new Spiral escalation has arrived.""")
    ActiveDocument.Close
    End Sub

    Private Sub cmdTechnical_Click()
    ActiveDocument.SaveAs "u:\Miscellaneous\Escalations\Callbacks - SV review\Technical\test.doc", wdFormatText
    Shell ("c:\windows\system32\net.exe send alonb ""Alon, a new Technical escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send badery ""Bader, a new Technical escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send garyn ""Gary a new Technical escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send yaacovp ""Jacob, a new Technical escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send martynf ""Martyn, a new Technical escalation has arrived.""")
    ActiveDocument.Close
    End Sub

    [/vba]

    It ran once then stopped.

    When I click on the template it opens the new document, but the code is not included.

    I am totally bewildered here.

    Cheers,
    Aaron
    Last edited by Merkava; 09-18-2006 at 11:37 AM.

  9. #9
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I am sorry, but you have to really get the details to us.

    When I click on the template it opens the new document, but the code is not included.
    What does click on the template mean? Right now, this phrase means nothing to me. You click on it in Windows Explorer? You click on, as a icon on the desktop?

    What do you mean the code is not included?

    Look, a template (properly used) is cloned. That is, a COPY of it is made into a new document. This copy will include all code that is in the original template.

    You mentioned that the template is closed unchanged. If this is what you are doing, then this is not a template being used properly. If a template is used correctly, the template file itself is NEVER OPENED, and therefore is NEVER changed.

    You must tell us, again, what you meaning by "form". Normally things with procedures using cmdWhatver, means a userform. That is, a dialog created in VBA that is displayed to the user.

    Now, it IS possible to insert commandbuttons (ActiveX commandbuttons) right in the document itself. If this is what you are doing - then please say so.

    However, your Step 3 about clicking a Save button certainly makes me think you are displaying a userform. You have not stated this, and I wish you would say so, one way or the other.

    Again, properly used, a template file (.DOT) makes a clone of itself, including any code. The original is not touched.

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Oh, and could you please use the underscore character (_) in your code? This makes the display in the code window here easier to read.

  11. #11
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location
    Hi,

    I have created a template, whatever.dot, in this template I have a table with several controls on it such as command buttons. When I look at the Icon in windows explorer I click on the template icon that represents the template that I have created. A document is then opened.

    I then press a command button that I have added to the template, and nothing happens.

    When I was working on the template, I ran the "template" and the buttons worked.

    If it would help I am quite willing to proved the template.

    T.I.A.

    Cheers,
    Aaron

  12. #12
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Sure, post the document.

    OK, you have cleared things up a bit. You have a .DOT file with an ActiveX commandbutton in it. Correct? That is, the commandbutton was placed in the document using the Controls toolbox.

    You right clicked the commandbutton, and put whatever code you wanted.

    You saved the file as a .DOT file.

    You double click the .DOT file, in Windows Explorer, and you get a new document.

    Now....you are saying that the commandbutton does NOT work. Correct?

    I can not duplicate this. I just did all of the above steps...and the commandbutton works in the new document.

  13. #13
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location
    Hi,

    I have attached the dot in the zip file. Any assistance would be greatly appreciated. Like I've said thios is my first venture into the wonderful world of Word programming. It worked once then basically died.

    I am probably doing something stupid

    Cheers,
    Aaron

  14. #14
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    1. Uh...did you really think that:[vba]Private Sub cmdTechnical_Click()
    ActiveDocument.SaveAs "u:\Miscellaneous\Escalations\Callbacks - " & _
    "SV review\Technical\test.doc", wdFormatText
    ' etc etc
    [/vba]would work for me. I don't have u:\blah blah blah on my machine.

    Next time, think about this and clear out, or comment things that you know are not applicable.

    So. I changed:[vba]Private Sub cmdTechnical_Click()
    ActiveDocument.SaveAs "u:\Miscellaneous\Escalations\Callbacks - " & _
    "SV review\Technical\test.doc", wdFormatText
    Shell ("c:\windows\system32\net.exe send alonb _
    ""Alon, a new Technical escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send badery _
    ""Bader, a new Technical escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send garyn _
    ""Gary a new Technical escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send _
    yaacovp ""Jacob, a new Technical escalation has arrived.""")
    Shell ("c:\windows\system32\net.exe send _
    martynf ""Martyn, a new Technical escalation has arrived.""")

    ActiveDocument.Close
    End Sub[/vba]to[vba]Private Sub cmdTechnical_Click()
    MsgBox "cmdTechnical works."
    End Sub[/vba]and...guess what? They all work.

    I unzipped your file .DOT. Double clicked it in Explorer. It created a new document - and once I changed the instructions that will not work on my machine - I don't HAVE a u: drive - the commandbuttons work.

    What does that tell you?? Hmmmm?

    Maybe YOU should try the same thing? Comment out your net.exe send lines. Have a message box like mine - or something else if you prefer. Try that. I am willing to bet that, as I have said all along...your commandbuttons are working. If it is NOT doing what you think it should...it is not the commandbuttons fault.

  15. #15
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    PS...please note my use of the underscore character to make the code lines shorter.

  16. #16
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location
    Hi,

    I realize that you probably don't have that particular drive setup. I also can have a message box pop up whenever I need one to, but that is not what I am trying to do.

    I left the entire code in so that maybe you could possibly see if the VB code that I was using was causing some kind of problem. And trust me I was never blaming the buttons, I have always blamed the code that I was using.

    Cheers,
    Aaron

  17. #17
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Not blaming the buttons? Hmmm, I do not think that is accurate.

    OK. Look at your code and please tell us what IS happening, because you ARE stating that nothing is happening...and I don't believe you.

    Your code does THREE things.

    1. perform a SaveAs
    2. do a bunch of net.exe send stuff
    3. close the document

    This is a Word VBA forum. So - you tell me...

    1. Is the document SavedAs? If yes, then, #1 worked.


    If your net.exe is not working correctly...then it is net.exe making your problem isn't it? If nothing at all is happening - which i doubt - then there is a parsing error as VBA tries to parse the code. The reason I doubt it is that.....

    wait a second....you DO have Option Explicit in your code module, right?

    Anyway, sorry, but this is not - as far as I can see - a Word, or a VBA problem. Your Shell statements are likely incorrect.

    Your original post, regarding filling out a document etc etc etc, are very do-able. If you want to get back to that, then fine. But issue sure does not seem to be anything to do with a template, or no code being in the new document, or the commandbuttons.

    Check your syntax for net.exe. I can't help you there. I have no idea what the syntax might be.

  18. #18
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location
    Hi,

    What I will do is start again and go step by step, once each step works I will go to the next step. I will keep you informed of the progress of this.

    When it is finished, I will want to protect the template. Do I use:

    1)tracked changes
    2)comments
    3)Forms

    Cheers,
    Aaron

  19. #19
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    As Gerry has already said there is nothing wrong with your code - as far as it goes. It is difficult to advise without knowing a bit more about the final process. How do you intend to populate the combo boxes, for example?

    ActiveX controls don't lend themselves to document protection - quite the reverse in fact. If you want protection, use Form controls - textboxes are straightforward, dropdowns are limited to 25 entries, and yiou don't have buttons; you can, however, create your own toolbar which will serve the same purpose.

    I have very quickly taken your template and changed it to a Word Form with a toolbar and attached it here - see if it helps.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  20. #20
    VBAX Regular
    Joined
    Sep 2006
    Posts
    15
    Location
    Thanks Tony,

    This is great, if I am using form controls I can populate the controls the in advance (just as you have done here). This actually makes the form "lighter" since I don't need arrays and all the additional code. The question is, how do I "read" the controls to see what was chosen. For example; On the 'approved by' drop down I chose Margaret Thatcher. When the user presses one of the buttons on the toolbar, how do I retrieve the name 'Margaret Thatcher' and put it into a variable in the code. So I could do something like this:

    strname= 'approved by drop down'
    Shell ("c:\windows\system32\net.exe send" & strname & ""a new Financial form has arrived.""")

    Basically the entire proccess can be narrowed down to the following:
    User End
    =================================
    1) User fills in form
    2) User clicks on button to "send" the form

    Form
    =================================
    Once button is pressed
    1) required fields are validated **
    2) form is saved to new location
    3) message is sent to receipient
    4) form is closed

    **If not validated the form won't be sent

    Cheers,
    Aaron

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •