how can I select a doc to import??

G

Guest

hi to all of you... I am importing a word document that some people send to
me and at this point, I cannot choose which document I want to import.


My code is the following:

Dim oDoc As Object 'Word.Document

Set oDoc = GetObject("C:\Documents and Settings\luva\My Documents\Base de
datos\ComputerRepair3.doc")

and it's working well but as you can see, it only gets the ComputerRepair3
and I need to choose wich one...

I tried something like this but it's not working....

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

strDocName = "C:\Documents and Settings" & _
InputBox("Enter the name of the Word doc " & _
"you want to import:", "Import Document")

Set appWord = GetObject(, "Word.Application")
Set doc = appWord.Documents.Open(strDocName)


ok, any ideas????? thank you in advance for your help!
 
G

Guest

thank you brendan for your help.... It looks kind of difficult for me.... is
there any other way that you think that is easy to do, or please if you are
able, can you explain to me where do I have to put all that code.....

ok, thank you again for your help.
 
B

Brendan Reynolds

Copy everything from "'***************** Code Start **************" down to
the end, and paste it into a new, standard module (not a form, report, or
class module).

Now look at the example in the web page, *before* the 'Code Start' line ...

Dim strFilter As String
Dim strInputFileName as string

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)

This sets up the filter to show only Excel files. As you want Word files,
just change 'Excel' to 'Word' and 'XLS' to 'DOC', e.g. ....

strFilter = ahtAddFilterItem(strFilter, "Word Files (*.DOC)", "*.DOC")

That's the only change you need to make.

When this code runs, the dialog will be displayed, and after the dialog is
closed, the variable strInputFileName will contain the name of the file
chosen by the user.
 
G

Guest

hi brendan... that worked great, but actually, after I did it I realised that
it's not doing what I need it to do... I don't know if I have to cut
something from the code or if I have to do something else.

let me post a bit of my code....

Private Sub GetWordDocument_Click()

Dim oDoc As Object 'Word.Document
Dim strUrgency As String
Dim lngUrgency As Long
Dim strEmployeeName As String
Dim lngEmployeeID As Long
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strdescriptionHWnotWorkingProperly As String


'Open the document in an instance of Word
Set oDoc = GetObject("C:\Documents and Settings\luva\My
Documents\ComputerRepair3.doc")


'Get the contents of the formfields
strUrgency = oDoc.formfields("Dropdown5").result
strEmployeeName = oDoc.formfields("Text7").result

'Get UrgencyId from Urgency Name by looking it up
lngUrgency = DLookup("[id_urgency]", "Urgency", "[desc_urgency] = '"
& strUrgency & "'")
lngEmployeeName = DLookup("[id_employee]", "Employees", "[name] = '"
& strEmployeeName & "'")


'Close the document without saving
oDoc.Close False

'appending the new record to the table
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\luva\My Documents\" & _
"Nueva.mdb;"
rst.Open "CRR Test", cnn, _
adOpenKeyset, adLockOptimistic

With rst
.AddNew
!id_urgency = lngUrgency
!id_employee = lngEmployeeName
.Update
.Close
End With
If blnQuitWord Then appWord.Quit
cnn.Close
MsgBox "CRR Imported!"

Cleanup:
Set rst = Nothing
Set cnn = Nothing
Set oDoc = Nothing
Exit Sub

End Sub


See that I'm only choosing that ComputerRepair3.doc????? well, when I put
the code you gave me in, the open file window appears, I choose a file doc,
and when I click on open, the save file window opens and I hit save (thing
that I don't really need to do) an error happens as it can't grab the
information from that document... it starts debugging at "strUrgency =
oDoc.formfields("Dropdown5").result".... so I'm not sure what I need to do...
do you know?? jajaa. it's kind of confussing for me and I don't how to
explain myself very good in english either... jajaa...

ok, if you understand what I tried to say, and you know what I need to do, I
would really appreciate it. and thank you again for all your help.
 

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