Solved

Transfering an combo box value as text to MS Word

Posted on 2002-05-16
8
244 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now