Solved

Transfering an combo box value as text to MS Word

Posted on 2002-05-16
8
274 Views
Last Modified: 2006-11-17
If i export data from a form to MS Word, the value of an combo box will be shown (in MS word) as a number (because the data type is number). However i want the selected text to be shown. Is this possible ?

For the export to MS Word i use the following code:

Private Sub Command190_Click()
 On Error GoTo MergeButton_Err

    Dim objWord As Word.Application

    'Start Microsoft Word 97.
    Set objWord = CreateObject("Word.Application")

    With objWord
        'Make the application visible.
        .Visible = True

        'Open the document.
        .Documents.Open ("C:\Aanvraagtest.doc")

        'Move to each bookmark and insert text from the form.
        .ActiveDocument.Bookmarks("Functie").Select
        .Selection.Text = (CStr(Forms!Aanvraag!Functie))
             
   
    End With
 

MergeButton_Err:
    'If a field on the form is empty, remove the bookmark text, and
    'continue.
    If Err.Number = 94 Then
        objWord.Selection.Text = ""
        Resume Next
End If

       Exit Sub
End Sub





0
Comment
Question by:ibs002
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 5

Expert Comment

by:bob_online
ID: 7013794
Can I assume that Aanvraag is the name of the form
and that Functie is the name of the combo box?

if so, add .Text, like this

.Selection.Text = (CStr(Forms!Aanvraag!Functie.Text))
0
 

Author Comment

by:ibs002
ID: 7013867
The assumptions of bob online are correct.

The combo box is based on the table "Functie" which has two columns the first is the ID the second is the "Description". The ID is exported to MS Word instead of the description. If I add .text to it like bob said it does not work. Anyone ?
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 7013989
what do you mean "it does not work"...do you get an error message?

If so, what error do you get?  

Can you set a break-point at the line that "does not work" and examine what the actual value is at that point.

Arthur Wood
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 2

Expert Comment

by:fcco
ID: 7014232
Hi,

your combobox is bounded to a hidden collum (probebly the Id field of your table). Therfore if you wan't the data from the combox, it'll return a number (the id). Therefore you need to rebound your combo box to the text field!

good luck!
0
 
LVL 2

Expert Comment

by:fcco
ID: 7014237
try these else!

.Selection.Text = (CStr(Forms!Aanvraag!Functie(1)))
.Selection.Text = (CStr(Forms!Aanvraag!Functie.description))

Maby it's easier to first asign the right data to a variable and then say

.Selection.Text = Variable

just a hint :-)
0
 

Author Comment

by:ibs002
ID: 7015693
If I follow the suggestion of fcco, i get the message
"The value you entered isnt't valid for this field, you may have entered text in a numeric field".
This is correct because the field functie in the table aanvraag is an numeric field. I can't change this in a text field because it's based on other queries.

I also try the suggestions of bob online and fcco but when i transport the data to word the bookmark functie displays as follow: [Functie]

I don't know how to assign the right data to a variable.
0
 
LVL 5

Accepted Solution

by:
bob_online earned 50 total points
ID: 7016076
Strange -- it appears it's assigning the datasource rather than the text value in the combo box.  The .Text should work -- it must have something to do with the interaction between access and word.  Give this one a try:

Selection.Text = (CStr(Forms!Aanvraag!Functie.Column(1)))

If your combo is based on a two column table, with id in column 0 and description in column 1, it's possible this will work even though .text isn't
   
   

0
 

Author Comment

by:ibs002
ID: 7016122
It works, thanks very much !!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question