Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Transfering an combo box value as text to MS Word

Posted on 2002-05-16
8
Medium Priority
?
297 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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 200 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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