Solved

Transfering an combo box value as text to MS Word

Posted on 2002-05-16
8
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

617 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