PDA

View Full Version : open a word document (hidden) via access



OTWarrior
10-25-2007, 03:21 AM
To put it simply, I want to click a button on an access form, which will bring up an open dialog box, and when you select the file, information is copied from the file into textboxes on the form.

Unfortunatley, I am having trouble with the first part (opening the document via access). Here is my code so far:


Private Sub lblImport_Click()
On Error GoTo ImportError
Dim objWord As Object
GetObject ("word.application")
' Set objWord = CreateObject("Word.Application")
' objWord.Visible = True
'Else
'Set objWord = GetObject("Word.Application")
' objWord.Visible = True
'End If

'Browsefile = FindFile("heloo", GetSystemNameLabel & _
'" ~ Please select RSP rev3 to import from", "(*.doc)", "*.doc")
With Dialogs(wdDialogFileOpen)
If .Display <> -1 Then
Exit Sub
Else
Set Browsefile = Word.Application.Documents.Open(WordBasic.FileNameInfo$(.name, 1), _
, , , , , , , , , , False)
End If
Me.txtPostCode = Browsefile.FormFields("Postcode").Result
If Browsefile.FormFields("chkMale").CheckBox = True Then
Me.txtGender = "Male"
Else
Me.txtGender = "Female"
End If
objWord.Quit wdDoNotSaveChanges
End With
Exit Sub
ImportError:
Word.Application.Quit wdDoNotSaveChanges
End Sub

what have i done wrong here?
(i have left some stuff remmed out that i did try)

Oorang
10-25-2007, 07:57 AM
Well I think you are going about this the hard way. Can you post a copy of the word file you are trying to tap, I have an idea I'd like to try out.

OTWarrior
10-25-2007, 08:17 AM
I can't post an actual copy, but here is an example:
(the way the actual document is laid out is the same as the example, with the form fields being in a table)

the formfield bookmark names are: name, adress1, postcode

OTWarrior
10-25-2007, 08:35 AM
After you said about me going about it in a confusing way i had another idea:

Me.txtPostCode = ActiveDocument.FormFields("Postcode").Result

This is all i need for each field. so long as the document is open (with the other code i had the user would have to always save it anyway, this way they can open it from outlook when they receive it).

plus, it is quick.

the only problem i now have is checking to see if the document (or word) is open.

is that the kind of thing you were thinking would be better?