Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

Transfering an combo box value as text to MS Word

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
ibs002
Asked:
ibs002
  • 3
  • 2
  • 2
  • +1
1 Solution
 
bob_onlineCommented:
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
 
ibs002Author Commented:
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
 
Arthur_WoodCommented:
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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
fccoCommented:
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
 
fccoCommented:
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
 
ibs002Author Commented:
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
 
bob_onlineCommented:
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
 
ibs002Author Commented:
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.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now