Results 1 to 11 of 11

Thread: [RESOLVED] There's got to be a better way...

Hybrid View

  1. #1

    Thread Starter
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: There's got to be a better way...

    I've not yet tried the code in my actual document. Before implementing it I added it to a document on it's own to try and understand it a little better.

    The code has been slightly modified from original because I could'nt get it to work, although it still doesn't work - I'm simply adding Array(5,2) to my document.

    Any help would be appreciated.
    Attached Files Attached Files
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  2. #2
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brugge, Belgium
    Posts
    208

    Re: There's got to be a better way...

    VB Code:
    1. Private Sub CommandButton1_Click()
    2.  
    3. 'you define an array of all your prices and string variables
    4. Dim A As Variant
    5. Dim x As Integer
    6. Dim chkMyCheck As Control
    7. Dim MainPriceControlArray(5, 2) As String
    8.  
    9.     MainPriceControlArray(1, 1) = "100.00" '    strCheckBox1 = "100.00"
    10.     MainPriceControlArray(2, 1) = "200.00" '    strCheckBox2 = "200.00"
    11.     MainPriceControlArray(3, 1) = "300.00" '    strCheckBox3 = "300.00"
    12.     MainPriceControlArray(4, 1) = "400.00" '    strCheckBox4= "400.00"
    13.     MainPriceControlArray(5, 1) = "500.00" '    strCheckBox5 = "500.00"
    14.    
    15.     [B]MainPriceControlArray(1, 2) = "textbox1" '    strProtectionCovers[/B]
    16.     MainPriceControlArray(2, 2) = "strCheckBox2" '    strChainShorteners
    17.     MainPriceControlArray(3, 2) = "strCheckBox3" '    strDetachTopBar
    18.     MainPriceControlArray(4, 2) = "strCheckBox4" '    strFireExtingExt
    19.     MainPriceControlArray(5, 2) = "strCheckBox5" '    strFireExtingInt
    20.    
    21. 'then you loop through your array and controls in the document
    22. ' you check each  control for it's anabled and value property and take the appropriate action
    23.  
    24.     For x = 1 To UBound(MainPriceControlArray)
    25.         For Each chkMyCheck In Me.Controls
    26.             If [B]LCase(Left(chkMyCheck.Name, 3)) = "che"[/B] Then
    27.                 If chkMyCheck.Enabled = True And chkMyCheck.Value = False Then
    28.                     [B]Me.Controls(MainPriceControlArray(x, 2)) [/B] = vbCr & chkMyCheck.Caption & vbTab & "$" & vbTab & MainPriceControlArray(x, 1)
    29.                 Exit For
    30.                 End If
    31.             End If
    32.         Next chkMyCheck
    33.     Next
    34.    
    35.  
    36.  
    37.     With ActiveDocument
    38.     .Bookmarks("Test").Range.Text = MainPriceControlArray(5, 2)
    39.     End With
    40. End Sub

    the bold sections I've changed
    Attached Files Attached Files

  3. #3

    Thread Starter
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: There's got to be a better way...

    Killazzz,

    I don't know if it's something I'm doing, but this doesn't seem to work. Unless I check checkbox 5, I simply get an error.

    And if I do check checkbox5, only that value appears at my bookmark.

    What I am trying to do is generate a list at my bookmark, which contains all items that are enabled yet false. For example, if checkbox1 and checkbox2 were the only boxes left that were both enabled and unchecked, then I would get:

    Checkbox1.caption "£" Checkbox1 item price
    Checkbox2.caption "£" Checkbox2 item price

    And there would be tabs in between the caption, "£" and the price (the tab positions are built into the style in the word document).

    Any ideas how I might resolve this?
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  4. #4
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brugge, Belgium
    Posts
    208

    Re: There's got to be a better way...

    This should do the trick
    Attached Files Attached Files

  5. #5

    Thread Starter
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: There's got to be a better way...

    Works perfectly Killazz (although it'll probably take a while for me to fully appreciate what it's doing )

    Thanks a lot for your help.
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

Posting Permissions

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



Click Here to Expand Forum to Full Width