ACCESS + WORD VBA

I

iris

Hello everybody.

I have a table in access with 12 columns.

I have created a form in WORD with 1 combobox and 12 textboxes.

I need to populate the textboxes with values when I choose a value in the
combobox...

can anyone tell me how to do that?
 
R

ryguy7272

I'm trying to imagine your design; nothing I can think of makes sense. Have
you taken a look at Mail Merge. That may work for you. As an alternative,
you can set up a Form, choose the appropriate record(s) and then run some VBA
code to push all the data from Access to Word. Take a look at this, and
change the variable names to match your own:

Option Compare Database


Sub PatientForm()

Dim appWord As Word.Application
Dim doc As Word.Document
Dim objWord As Object

On Error Resume Next
err.Clear

Set appWord = GetObject(, "Word.Application")
Set objWord = CreateObject("Word.Application")

If err.Number <> 0 Then

objWord.Documents.Open CurrentProject.Path & "\test.doc"
objWord.Visible = True

End If
'Set doc = appWord.Documents.Open("C:\PatientForm.doc", , True)
Set doc = appWord.Documents.Open(CurrentProject.Path & "\PatientForm.doc", ,
True)
With doc

..FormFields("LastName").Result = Forms!SearchForm!frmsubClients.Form.LastName
..FormFields("FirstName").Result =
Forms!SearchForm!frmsubClients.Form.FirstName
..FormFields("ConsultDate").Result =
Forms!SearchForm!frmsubClients.Form.ConsultDate

..Visible = True
..Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox err.Number & ": " & err.Description

End Sub


Regards,
Ryan---
 
I

iris

Hi Ryan,

thank you for your quick reply.

I open the form from WORD and not from Access... the data base is in access...

The enduser is supposed to use this data in his document.

I need the code in word vba that pulls the data from access to textboxes in
a word form...
 
I

iris

Hi Ryan

Thank you for caring.

After Gregs answer I tried a different approach and now everything is
working like a swiss watch!

Thank You again!

Have a nice day!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top