Results 1 to 4 of 4
  1. #1
    alexandre
    Guest

    Populate combobox with data from a SQL table (vba/word2k)

    I would like to populate a Form Combo Box with data from a SQL database table.
    When the user makes his selection, I then want to populate the document with data from the other fields based on the selection.
    Any ideas?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Populate combobox with data from a SQL table (vba/word2k)

    You can use ADO code from any of the Office 2k apps to connect to a datasource and return a recordset. Depending on how many rows you will wind up with in the combobox, you may need to create a callback routine to populate that, but then you can use the combobox selection as the criteria for creating a new recordset from the same ADO connection. Since you want to connect to SQL Server, you'll need a valid login and password to pass in the connection or you'll need to use a datalink that contains a trusted link based on your windows login.
    Charlotte

  3. #3
    alexandre
    Guest

    Re: Populate combobox with data from a SQL table (vba/word2k)

    Charlotte,

    Thank you for your response...

    I just want the sname field from the Luser database, luser1 table into the combobox.
    Where do I add the procedure?
    Also once I have the selection made from the combobox, I then want to put the contents of the other fields into the new document.

    Would it be best to capture the row into a temporary array and then populate the new document or can we populate the document directly with resulting data?


    Any input is greatly appreciated...
    I am attaching a population procedure...

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Populate combobox with data from a SQL table (vba/word2k)

    I don't usually program Word, so I can't be of too much help off the top of my head. Your code will go into a macro, but where it's called from will depend on exactly what you're doing.

    With ADO, you can use the same connection to retrieve the values for the combobox and then to return a recordset based on the selected value, but the two things wouldn't be in the same routines. If you use the recordset, you don't really need to populate an array from it, you can use it directly. The only time you really need an array for data is if you read data from a text file and need a place to store it temporarily until you can use it.

    You might consider posting the question in the Word forum as well, but if you do, make sure you indicate in your post that it's also posted here just to keep people from answering you twice, one in each forum.
    Charlotte

Posting Permissions

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