Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Feb 2004
    Location
    Hellevoetsluis, Netherlands
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Select case Word (Word 2k )

    Hi,

    I need to do the following: in a combobox on a userform i've put four items. The item goes to a bookmark in the document. Now I want the item changes in a longer sentence so I understood to use Select case.

    This is what I have:

    If ActiveDocument.Bookmarks.Exists("bwLocatie") Then

    here I want to say Case cboLocatie = amsterdam change in full address string before placing it in the document

    ...... Range.Text = cboLocatie.Text
    End if

    Can someone help me with this?

    Sjaan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Select case Word (Word 2k )

    Hello Sjaan,

    Welcome to Woody's Lounge. I'm slightly confused by your description, could you try to explain in greater detail what you want to accomplish? It might also help if you posted more of the code you are using now.

  3. #3
    New Lounger
    Join Date
    Feb 2004
    Location
    Hellevoetsluis, Netherlands
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select case Word (Word 2k )

    Oke I try.

    In a userform I use several elements which the user have to fill in or make choices from comboboxes. After that they klik on a button and every value goes to a specific bookmark in the document. I do that with
    If ActiveDocument.Bookmarks.Exists(namebookmark) Then
    ActiveDocument.Bookmarks(namebookmark).Range.Text = Value textbox or combobox
    End if

    This works fine.

    Now there's one combobox with the items Rotterdam, Amsterdam, Utrecht and Eindhoven
    If the user chooses one the item is filled in in the document.

    But I want that if item is Rotterdam the value changes in Schorpioenstraat 51, (gebouw De Ster 1e etage) 3067 GG, Rotterdam. And if item is Utrecht something else.... and so on.

    Now I've been told to do that with Select Case. So I can say :


    Case cboLocatie = Rotterdam
    cboLocatie becomes ......

    There's an error when I write

    If ActiveDocument.Bookmarks.Exists("bwLocatie") Then

    Select Case cboLocatie
    Case cboLocatie = "Rotterdam"
    cboLocatie = "Schorpioenstraat 51 .... etc"

    ....
    End Case
    ActiveDocument.Bookmarks("bwLocatie").Range.Text = cboLocatie.Text
    End if

    Is that understandable (my english is not that good) ?

    Sjaan

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Select case Word (Word 2k )

    If I understand correctly, you don't need a Select Case here. You can store all the information you need in the combo box as follows:
    - Set the Column Count property of the combo box to 2.
    - Set the Column Widths property of the combo box to (for example) 100 pt,0 pt (if your system settings are Dutch, you need to use a semi-colon instead of a comma: 100 pt;0 pt)
    - In the Initialize event of the form, fill both columns of the combo box. The code could look like this:

    Private Sub UserForm_Initialize()
    Dim strArray(0 To 3, 0 To 1)
    strArray(0, 0) = "Amsterdam"
    strArray(0, 1) = "Kloveniersburgwal 33, 1012 AB"
    strArray(1, 0) = "Eindhoven"
    strArray(1, 1) = "Stationsplein 28, 5678 CD"
    strArray(2, 0) = "Rotterdam"
    strArray(2, 1) = "Schorpioenstraat 51, (gebouw De Ster 1e etage) 3067 GG"
    strArray(3, 0) = "Utrecht"
    strArray(3, 1) = "Catharijnesingel 16, 2345 EF"
    Me.cboLocatie.List = strArray
    End Sub

    In the code that sets the bookmark, you can refer to the columns of the combo box:

    If ActiveDocument.Bookmarks.Exists(namebookmark) Then
    ActiveDocument.Bookmarks(namebookmark).Range.Text = Me.cboLocatie.Column(1) & ", " & Me.cboLocatie.Column(0)
    End If

  5. #5
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select case Word (Word 2k )

    Hi Sjaan ,
    How about setting a string with the value you need and then applying the string to your bookmark ...

    dim strMyString as String
    Select Case cboLocatie
    Case cboLocatie = "Rotterdam"
    strMyString = "Schorpioenstraat 51 .... etc"

    ....
    End Case
    ActiveDocument.Bookmarks("bwLocatie").Range.Text = strMyString
    End if

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Select case Word (Word 2k )

    I'm not sure you still want to use Select....Case...End Select, but if you do, I believe the proper syntax is:

    Select Case variable
    Case value1
    'Code1
    Case value2
    'Code2
    Case Else
    'CodeElse
    End Select

    In other words, the left side of the equation is implicit (unless you do something like Is > x).

  7. #7
    New Lounger
    Join Date
    Feb 2004
    Location
    Hellevoetsluis, Netherlands
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select case Word (Word 2k )

    Thanks for the help. It works nice now. I choosed the solution with Select Case because my Version is Dutch while the version at work is English.

    I have some other questions but first I'll try to figure them out for myself.

    Thanks again...

    Sjaan PS Hans, you must be Dutch

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Select case Word (Word 2k )

    >> PS Hans, you must be Dutch

    Yes, I am - if you click on my user name, you'll see my profile.

Posting Permissions

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