Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 35 of 35

Thread: Adding/Deleting Rows in a Table

  1. #21
    VBAX Tutor
    Joined
    Nov 2005
    Posts
    225
    Location
    Hi Trudy,

    Just as soon as I solve the additional row problem I intend adding a further userform for the purpose of inserting various indorsements (i.e. short legal pleadings) into my document.

    I expect that the userform would have radio buttons (or a drop-down list so that I could choose what type of indorsement to add.

    The indorsements would be held as autotext and would be inserted into a bookmark in the manner you suggest.

    If you have done something similar I would be grateful if you were to provide me with an example of it.

    Regards,

    Greg.

  2. #22
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Here's a sample
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #23
    VBAX Tutor
    Joined
    Nov 2005
    Posts
    225
    Location
    Thanks MD,

    That worked beautifully when I first unzipped and opened it but try as I might I couldn't get it to work once I had saved it elsewhere. When I debugged, the curser stopped at frmTable.Show. I can't see why.

    Public Sub addTable()
    frmTable.Show (this seems to be the problem area)
    End Sub

    However, once I sort that out my hope would be to add that functionality to my existing userform.

    Indeed, if I was able to choose the number of defendants from the outset (or add/subtract them at will) I would want the existing userform to also offer me additional spaces to type in the names and addresses of those defendants.

    Do you have any ideas as to how that might be achieved?

    A better version of the document I regularly use is attached (I think).

    Regards,

    Greg.

  4. #24
    VBAX Tutor
    Joined
    Nov 2005
    Posts
    225
    Location
    Hi again,

    Further to my latest email, I see that your document is a Document template. That would explain why all my other related doucments have been affected by it. I wonder if this is necessary?

    Although your method works very nicely (initially at least), is there a way to add those rows that doesn't rely the use of a global template?

    Greg.

  5. #25
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I can't think of a method of doing whaty you're after to a Document that would be practical in day to day use. It is more appropriate to adjust your other code, which I haven't touched, to work in a new document based on a template rather than the other way round.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #26
    VBAX Tutor
    Joined
    Nov 2005
    Posts
    225
    Location
    Hi again Gerry. MD and Norrie have both been very helpful.

    MD has provided a method for adding rows to my table which works very well. However, I feel that its functionality needs to be incorporated into my exiting userform.

    Indeed, it would be ideal if, after choosing the number of extra defendants to be added via MD's form, but before the actual rows were added, a click event would bring up a further userform into which I could enter the names and addresses just as I am able to with my existing userform.

    If the added rows also contained bookmarks, I could then fillabookmark (and related ref fields) via the extra userform so that the document would then be populated with the new defendants' details.

    This is of course a long wish list and I know that I have to take this one step at a time. So, the first question is: Can it be done and if so, where do I start. Should I stick with MD's form and try to incorporate it into my existing userform or should I take another approach entirely?

    Any useful comments will be appreciated.

    Greg.

  7. #27
    Hi,

    I created my form using tables. The entries is made direct into the
    form not using UserForms. At a certain point the user may
    have to insert more information than there is room.
    Like we don't know how many warrants a person has outstanding.

    The rows/columns in the warrant section I copied into "AutoText"
    making sure it is attached to the document template (not global).

    The macro unprotects the form, goes to the bookmark
    "InsertNewWarrant" and inserts the new rows/columns
    from the AutoText and protects the form again.

    The user can now insert data into the new fields.


    [VBA]
    Sub InsertNewWarrant()

    ' Macro Insert a New Warrant
    ' Macro recorded 06/04/07 by engelent
    '
    ActiveDocument.Unprotect Password:=""

    Selection.GoTo What:=wdGoToBookmark, Name:="InsertNewWarrant"
    With ActiveDocument.Bookmarks
    .DefaultSorting = wdSortByName
    .ShowHidden = False
    End With

    Selection.MoveLeft Unit:=wdCharacter, Count:=1

    (I placed my bookmark one character to the right to ensure
    it will not be replaced by the AutoText insert - it will
    be pushed to the end so it is available for more inserts.)

    'Insert AutoText entry

    Application.DisplayAutoCompleteTips = False
    ActiveDocument.AttachedTemplate.AutoTextEntries("InsertNewWarrant").Insert _
    Where:=Selection.Range, RichText:=True

    ' Curser jumps to a specific spot in the table

    Selection.GoTo What:=wdGoToBookmark, Name:="agency"

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""


    End Sub
    [/VBA]
    I wanted to use UserForms but the powers to be here
    wanted to have direct entry into the form.

    Well, like I said, I am a newbie in VBA - but this form sits on our
    shared drive and is been in use since June by hundreds of users.
    No complaint so far! Amazing!

    I you would like me to post my complete form - I will strip it of sensative stuff and post it.

    Trudy

  8. #28
    VBAX Tutor
    Joined
    Nov 2005
    Posts
    225
    Location
    Thanks very much for that Trudy.

    I am curious to see what your document looks like and how that works for you in practice. Are you able to zip one up and make it available?

    Regards,

    Greg.

  9. #29

    Here is my template

    I hope it works for you. As you tab throught the different TextFormFields, different Toolbars will open.

    Have fun.
    Trudy

  10. #30
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Trudy,
    Why not add a macro to run on entry to open your dropdowns when you tab to them?
    [VBA]
    Sub DD()
    SendKeys "{F4}", True
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #31
    VBAX Tutor
    Joined
    Nov 2005
    Posts
    225
    Location
    Thanks Trudy,

    The many different tool bars look very useful but they don't work for me yet. I think the autotext entries may not have travelled with the document.

    Anyway, I'll have another look at it shortly.

    Greg.

  12. #32

    THANK YOU!! One more thing to make live easier

    Hi mdmackillop!

    You are a genius! Not only a Guru! This little macro, added to my form makes things easier for the users here!


    ***Sub DD()
    SendKeys "{F4}", True
    ****End Sub


    Thanks again
    Trudy

  13. #33
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    It's the little things that make the difference!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  14. #34

    Message to Greg

    Hi Greg, please make sure that the form is "Protected" or it won't work!

    Trudy

  15. #35
    VBAX Tutor
    Joined
    Nov 2005
    Posts
    225
    Location
    Hi Trudy,

    I have since realised this but thanks anyway.

    Greg.

Posting Permissions

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