18d59 Module For Importing Word Forms
Sign Up |  Live StatsLive Stats    Articles 37,332| Comments 177,286| Members 19,416, Newest Kaylee| Online 542
Home Contact
 (Forgotten?): 
    Sikhism
    For best SPN experience, use Firefox Internet Browser!


                                                                   Your Banner Here!    




Click Here to Register/Sign Up Daily Hukamnama Member Blogs Downloads Website Navigation Help Fonts Tags

Module For Importing Word Forms

Our Donation Goal : Why Donate? : Donate Today! : Donate Anonymously (ਗੁਪਤ) : Our Family of Supporters
Goal this month: 500 USD, Received: 115 USD (23%)
Please Donate...
     
Related Topics...
Thread Thread Starter Forum Replies Last Post
Word, Word Of God, Shabad, Naam :Exploration Sikh80 Gurmat Vichaar 6 19-Mar-2008 22:05 PM
Word by word translation of Triya Charitars 21, 22, 23 and 71 vijaydeep Singh Hard Talk 9 25-Dec-2006 19:49 PM
Importing data from forms in pdf to an existing access DB tope12 Information Technology 0 28-Jul-2006 08:34 AM
KBV - What's the difference between a module and a macro? KBV Information Technology 6 28-Jul-2006 08:30 AM
Help with Module brian b Information Technology 3 28-Jul-2006 08:24 AM


Tags
module, importing, word, forms
Reply Post New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!
  #1 (permalink)  
Old 19-Nov-2005, 22:00 PM
darreninwarrington@hotmail.co.uk's Avatar darreninwarrington@hotmail.co.uk
Guest
 
Posts: n/a
   
   
Module For Importing Word Forms

  Donate Today!   Email to Friend  Tell a Friend   Show Printable Version  Print   Contact sikhphilosophy.net Administraion for any Suggestions, Ideas, Feedback.  Feedback  

Register to Remove Advertisements
Morning all.

I'm after a little help on trying to automate a module used in an
Access project I have. The module simply imports data from a Word form
into a single table. The thing works fine but the code which I got from
the Microsoft MSDN library requires the user to enter the name of the
file they wish to import from (I've put the code at the end of this
message).

What I want to do is automate this somewhat and replace the code which
requests the file name with code that will simply import from every
word form that is in a given directory so that if there are 50 forms to
import, rather than run the module 50 times and typing in the filename
each time, the user simply runs the module once and it imports all 50
as 50 records in the table.

Any assistance or thoughts on this matter would be most appreciated.

D Hermes



The current module is as follows........

Sub GetWordData()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDocName As String
Dim blnQuitWord As Boolean

On Error GoTo ErrorHandling

strDocName = "C:\Contracts\" & _
InputBox("Enter the name of the Word contract " & _
"you want to import:", "Import Contract")

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

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/information-technology/7757-module-for-importing-word-forms.html
"Data Source=C:\Contracts\" & _
"Healthcare Contracts.mdb;"
rst.Open "tblContracts", cnn, _
adOpenKeyset, adLockOptimistic

With rst
.AddNew
!FirstName = doc.FormFields("fldFirstName").Result
!LastName = doc.FormFields("fldLastName").Result
!Company = doc.FormFields("fldCompany").Result
!Address = doc.FormFields("fldAddress").Result
!City = doc.FormFields("fldCity").Result
!State = doc.FormFields("fldState").Result
!ZIP = doc.FormFields("fldZIP1").Result & _
"-" & doc.FormFields("fldZIP2").Result
!Phone = doc.FormFields("fldPhone").Result
!SocialSecurity = doc.FormFields("fldSocialSecurity").Result
!Gender = doc.FormFields("fldGender").Result
!BirthDate = doc.FormFields("fldBirthDate").Result
!AdditionalCoverage = _
doc.FormFields("fldAdditional").Result
.Update
.Close
End With
doc.Close
If blnQuitWord Then appWord.Quit
cnn.Close
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=7757
MsgBox "Contract Imported!"


Cleanup:
Set rst = Nothing
Set cnn = Nothing
Set doc = Nothing
Set appWord = Nothing
Exit Sub
ErrorHandling:
Select Case Err
Case -2147022986, 429
Set appWord = CreateObject("Word.Application")
blnQuitWord = True
Resume Next
Case 5121, 5174
MsgBox "You must select a valid Word document. " _
& "No data imported.", vbOKOnly, _
"Document Not Found"
Case 5941
MsgBox "The document you selected does not " _
& "contain the required form fields. " _
& "No data imported.", vbOKOnly, _
"Fields Not Found"
Case Else
MsgBox Err & ": " & Err.Description
End Select
GoTo Cleanup
End Sub





Got anything to share on This Topic? Why not share your immediate thoughts/reaction with us! Login Now! or Sign Up Today! to share your views... Gurfateh!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 19-Nov-2005, 22:00 PM
Douglas J. Steele's Avatar Douglas J. Steele
Guest
 
Posts: n/a
   
   
Re: Module For Importing Word Forms

Assuming all the documents you want to import are in C:\Contracts, and have
an extension of .Doc, the following code will return all of the files in
that folder:

Dim strFolder As String

strFolder = "C:\Contracts\"
strDocName = Dir$(strFolder & "*.doc")
Do While Len(strDocName) > 0

' Put the rest of the code to do the import here.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=7757
' You're importing strFolder & strDocName,
' not strDocName

strDocName = Dir$()
Loop

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



wrote in message
news:1132391932.916873.116680@g49g2000cwa.googlegr oups.com...
> Morning all.
>
> I'm after a little help on trying to automate a module used in an
> Access project I have. The module simply imports data from a Word form
> into a single table. The thing works fine but the code which I got from
> the Microsoft MSDN library requires the user to enter the name of the
> file they wish to import from (I've put the code at the end of this
> message).
>
> What I want to do is automate this somewhat and replace the code which
> requests the file name with code that will simply import from every
> word form that is in a given directory so that if there are 50 forms to
> import, rather than run the module 50 times and typing in the filename
> each time, the user simply runs the module once and it imports all 50
> as 50 records in the table.
>
> Any assistance or thoughts on this matter would be most appreciated.
>
> D Hermes
>
>
>
> The current module is as follows........
>
> Sub GetWordData()
> Dim appWord As Word.Application
> Dim doc As Word.Document
> Dim cnn As New ADODB.Connection
> Dim rst As New ADODB.Recordset
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=7757
> Dim strDocName As String
> Dim blnQuitWord As Boolean
>
> On Error GoTo ErrorHandling
>
> strDocName = "C:\Contracts\" & _
> InputBox("Enter the name of the Word contract " & _
> "you want to import:", "Import Contract")
>
> Set appWord = GetObject(, "Word.Application")
> Set doc = appWord.Documents.Open(strDocName)
>
> cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=C:\Contracts\" & _
> "Healthcare Contracts.mdb;"
> rst.Open "tblContracts", cnn, _
> adOpenKeyset, adLockOptimistic
>
> With rst
> .AddNew
> !FirstName = doc.FormFields("fldFirstName").Result
> !LastName = doc.FormFields("fldLastName").Result
> !Company = doc.FormFields("fldCompany").Result
> !Address = doc.FormFields("fldAddress").Result
> !City = doc.FormFields("fldCity").Result
> !State = doc.FormFields("fldState").Result
> !ZIP = doc.FormFields("fldZIP1").Result & _
> "-" & doc.FormFields("fldZIP2").Result
> !Phone = doc.FormFields("fldPhone").Result
> !SocialSecurity = doc.FormFields("fldSocialSecurity").Result
> !Gender = doc.FormFields("fldGender").Result
> !BirthDate = doc.FormFields("fldBirthDate").Result
> !AdditionalCoverage = _
> doc.FormFields("fldAdditional").Result
> .Update
> .Close
> End With
> doc.Close
> If blnQuitWord Then appWord.Quit
> cnn.Close
> MsgBox "Contract Imported!"
>
>
> Cleanup:
> Set rst = Nothing
> Set cnn = Nothing
> Set doc = Nothing
> Set appWord = Nothing
> Exit Sub
> ErrorHandling:
> Select Case Err
> Case -2147022986, 429
> Set appWord = CreateObject("Word.Application")
> blnQuitWord = True
> Resume Next
> Case 5121, 5174
> MsgBox "You must select a valid Word document. " _
> & "No data imported.", vbOKOnly, _
> "Document Not Found"
> Case 5941
> MsgBox "The document you selected does not " _
> & "contain the required form fields. " _
> & "No data imported.", vbOKOnly, _
> "Fields Not Found"
> Case Else
> MsgBox Err & ": " & Err.Description
> End Select
> GoTo Cleanup
> End Sub
>



Reply With Quote
  #3 (permalink)  
Old 19-Nov-2005, 22:00 PM
Larry Daugherty's Avatar Larry Daugherty
Guest
 
Posts: n/a
   
   
Re: Module For Importing Word Forms

There are many, many different ways you might achieve your objective.
Some are elegant and some are crude. What needs doing is determined
by the constraints of your environment. I won't even try to list all
of the things you must consider. It's just that when you automate you
need to get out the crystal ball and anticipate the unexpected. You
probably don't want the code to halt with an error prompt when
processing the first of 200 Word documents.

If I were doing it, I'd probably ask the user to navigate to the
target and select the first file. [I'd use the API code that replaces
the Common Dialog Controls that can be found at www.mvps.org/access
It takes a lot of wrestling with the code to get it going properly but
it's a worthwhile thing to do. Using the API means that that part of
your code will be bulletproof across versions of Access and across
OSs]. I'd then parse out the path and use the Dir successively to
return the next filename that matches the pattern. Eventually the Dir
command will return an empty string and you know you're done. You
need to change the code you're using now to have the record set open
throughout the whole operation of looping through the code that
retrieves the next file and gathers the info. Write the new record
and continue looping. When you fall out of the loop do the required
housekeeping. When you're doing something like that for the first
time you're wise to plan to get acquainted with the debugger to verify
that the right things are happening when you think they are..

I recommend that you design first using pseudopodia and that you work
with just one piece at a time. For example, if you've never played
with the Dir command as I've suggested above, write a small routine to
just loop through a folder willed with Word documents returning the
names. Debug.Print is a good friend!

Good luck with it. Post back as questions arise.

HTH
--
-Larry-
--

wrote in message
news:1132391932.916873.116680@g49g2000cwa.googlegr oups.com...
> Morning all.
>
> I'm after a little help on trying to automate a module used in an
> Access project I have. The module simply imports data from a Word

form
> into a single table. The thing works fine but the code which I got

from
> the Microsoft MSDN library requires the user to enter the name of

the
> file they wish to import from (I've put the code at the end of this
> message).
>
> What I want to do is automate this somewhat and replace the code

which
> requests the file name with code that will simply import from every
> word form that is in a given directory so that if there are 50 forms

to
> import, rather than run the module 50 times and typing in the

filename
> each time, the user simply runs the module once and it imports all

50
> as 50 records in the table.
>
> Any assistance or thoughts on this matter would be most appreciated.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=7757
>
> D Hermes
>
>
>
> The current module is as follows........
>
> Sub GetWordData()
> Dim appWord As Word.Application
> Dim doc As Word.Document
> Dim cnn As New ADODB.Connection
> Dim rst As New ADODB.Recordset
> Dim strDocName As String
> Dim blnQuitWord As Boolean
>
> On Error GoTo ErrorHandling
>
> strDocName = "C:\Contracts\" & _
> InputBox("Enter the name of the Word contract " & _
> "you want to import:", "Import Contract")
>
> Set appWord = GetObject(, "Word.Application")
> Set doc = appWord.Documents.Open(strDocName)
>
> cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=C:\Contracts\" & _
> "Healthcare Contracts.mdb;"
> rst.Open "tblContracts", cnn, _
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=7757
> adOpenKeyset, adLockOptimistic
>
> With rst
> .AddNew
> !FirstName = doc.FormFields("fldFirstName").Result
> !LastName = doc.FormFields("fldLastName").Result
> !Company = doc.FormFields("fldCompany").Result
> !Address = doc.FormFields("fldAddress").Result
> !City = doc.FormFields("fldCity").Result
> !State = doc.FormFields("fldState").Result
> !ZIP = doc.FormFields("fldZIP1").Result & _
> "-" & doc.FormFields("fldZIP2").Result
> !Phone = doc.FormFields("fldPhone").Result
> !SocialSecurity = doc.FormFields("fldSocialSecurity").Result
> !Gender = doc.FormFields("fldGender").Result
> !BirthDate = doc.FormFields("fldBirthDate").Result
> !AdditionalCoverage = _
> doc.FormFields("fldAdditional").Result
> .Update
> .Close
> End With
> doc.Close
> If blnQuitWord Then appWord.Quit
> cnn.Close
> MsgBox "Contract Imported!"
>
>
> Cleanup:
> Set rst = Nothing
> Set cnn = Nothing
> Set doc = Nothing
> Set appWord = Nothing
> Exit Sub
> ErrorHandling:
> Select Case Err
> Case -2147022986, 429
> Set appWord = CreateObject("Word.Application")
> blnQuitWord = True
> Resume Next
> Case 5121, 5174
> MsgBox "You must select a valid Word document. " _
> & "No data imported.", vbOKOnly, _
> "Document Not Found"
> Case 5941
> MsgBox "The document you selected does not " _
> & "contain the required form fields. " _
> & "No data imported.", vbOKOnly, _
> "Fields Not Found"
> Case Else
> MsgBox Err & ": " & Err.Description
> End Select
> GoTo Cleanup
> End Sub
>



Reply With Quote
  #4 (permalink)  
Old 19-Nov-2005, 22:00 PM
darreninwarrington@hotmail.co.uk's Avatar darreninwarrington@hotmail.co.uk
Guest
 
Posts: n/a
   
   
Re: Module For Importing Word Forms

  Donate Today!  
Hi Doug and many thanks for the information. I've added in the
suggested lines of code but now find that I get an error occurring when
running the module. It is one of the errors covered by the error
handling lines at the end of the code - the "You must select a valid
Word document. No data imported." error. The is despite the fact that
the C:\Contracts\ folder contains several valid Word documents, all of
which can be imported manually using the original code that requires
entering the filename.

Any ideas on what might be causing this error? Just in case I've caused
it by adding in your suggested lines in the wrong place, I've pasted
the revised code below.

Thanks once again. Darren.



Sub GetWordData()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDocName As String
Dim blnQuitWord As Boolean
Dim strFolder As String

On Error GoTo ErrorHandling

strFolder = "C:\Contracts\"
strDocName = Dir$(strFolder & "*.doc")
Do While Len(strDocName) > 0

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

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Contracts\" & _
"Healthcare Contracts.mdb;"
rst.Open "tblContracts", cnn, _
adOpenKeyset, adLockOptimistic

With rst
.AddNew
!FirstName = doc.FormFields("fldFirstName").Result
!LastName = doc.FormFields("fldLastName").Result
!Company = doc.FormFields("fldCompany").Result
!Address = doc.FormFields("fldAddress").Result
!City = doc.FormFields("fldCity").Result
!State = doc.FormFields("fldState").Result
!ZIP = doc.FormFields("fldZIP1").Result & _
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=7757
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=7757
"-" & doc.FormFields("fldZIP2").Result
!Phone = doc.FormFields("fldPhone").Result
!SocialSecurity =
doc.FormFields("fldSocialSecurity").Result
!Gender = doc.FormFields("fldGender").Result
!BirthDate = doc.FormFields("fldBirthDate").Result
!AdditionalCoverage = _
doc.FormFields("fldAdditional").Result
.Update
.Close
End With
doc.Close
If blnQuitWord Then appWord.Quit
cnn.Close

strDocName = Dir$()
Loop

MsgBox "Contracts Imported!"


Cleanup:
Set rst = Nothing
Set cnn = Nothing
Set doc = Nothing
Set appWord = Nothing
Exit Function
ErrorHandling:
Select Case Err
Case -2147022986, 429
Set appWord = CreateObject("Word.Application")
blnQuitWord = True
Resume Next
Case 5121, 5174
MsgBox "You must select a valid Word document. " _
& "No data imported.", vbOKOnly, _
"Document Not Found"
Case 5941
MsgBox "The document you selected does not " _
& "contain the required form fields. " _
& "No data imported.", vbOKOnly, _
"Fields Not Found"
Case Else
MsgBox Err & ": " & Err.Description
End Select
GoTo Cleanup
End Sub

Reply With Quote
   Click Here to Donate Now!

Support Us!
Become a Promoter!
Gurfateh ji, you can become a SPN Promoter by Donating as little as $10 each month. With limited resources & high operational costs, your donations make it possible for us to deliver a quality website and spread the teachings of the Sri Guru Granth Sahib Ji, to serve & uplift humanity. Every contribution counts. Donate Generously. Gurfateh!
ReplyPost New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!

Bookmarks


(View-All Members who have read this thread : 0
There are no names to display.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Tools Search
Search:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

» Active Discussions
Woolwich Killing: The...
Today 03:50 AM
2 Replies, 47 Views
Rozana Reports (ਪੰਜਾਬੀ...
Today 03:09 AM
316 Replies, 7,627 Views
Sikh Spokesman (ਪੰਜਾਬੀ...
Today 03:00 AM
179 Replies, 4,530 Views
How does Sikhi help you...
Today 00:52 AM
31 Replies, 972 Views
Transgenderism ... Right...
By Kaylee
Today 00:33 AM
25 Replies, 1,246 Views
Losing My Religion: Why...
Today 00:00 AM
14 Replies, 373 Views
Occultism - Rejection in...
Yesterday 23:57 PM
61 Replies, 2,619 Views
Kirtan
Yesterday 21:24 PM
0 Replies, 32 Views
Panjabi
Yesterday 21:22 PM
15 Replies, 302 Views
Keeping Amrit Vela
Yesterday 16:49 PM
12 Replies, 936 Views
Do you believe in...
Yesterday 15:08 PM
196 Replies, 4,106 Views
Black Sikhs?
Yesterday 06:33 AM
20 Replies, 5,870 Views
Man Driving Without...
Yesterday 05:06 AM
5 Replies, 147 Views
Request for assistance...
Yesterday 04:24 AM
8 Replies, 97 Views
Health Exercise And...
Yesterday 02:10 AM
1 Replies, 97 Views
» Books You Should Read...
Powered by vBadvanced CMPS v3.2.3
All times are GMT +6.5. The time now is 04:32 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2 Copyright © 2004-12, All Rights Reserved. Sikh Philosophy Network


Page generated in 0.51096 seconds with 32 queries
0