Sign Up |  Live StatsLive Stats    Articles 35,345| Comments 159,790| Members 17,820, Newest waheguruhelpme| Online 225
Home Contact
 (Forgotten?): 
    Sikhism

   
                                                                     Your Banner Here!    

Sikh Philosophy Network » Sikh Philosophy Network » Current Affairs » Information Technology » Taking a Word form and using it to fill in parts of an Access form

Taking a Word form and using it to fill in parts of an Access form

Our Donation Goal : Why Donate? : Donate Today! : Donate Anonymously (ਗੁਪਤ) : Our Family of Supporters
Goal this month: 400 USD, Received: 35 USD (9%)
Please Donate...
Related Topics...
Thread Thread Starter Forum Replies Last Post
How to change Access Startup form from a form combo box? jhutchings@eadmotors.com Information Technology 3 28-Jul-2006 08:23 AM
Access 2000 Multiline field or word wrap in text box in form Mark Information Technology 1 28-Jul-2006 08:12 AM
we make Form in Access is it possible to open only form Naveed Information Technology 2 28-Jul-2006 08:05 AM
How do I merge recipes from access into word in book form? AGMPreacher Information Technology 1 11-Nov-2005 20:08 PM
Fill in MS Word template from Access Si Information Technology 3 08-Nov-2005 12:53 PM


Tags
taking, word, form, using, fill, parts, access
Reply Post New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!
  #1 (permalink)  
Old 28-Jul-2006, 08:41 AM
AmandaH's Avatar AmandaH
Guest
 
Posts: n/a
   
   
Taking a Word form and using it to fill in parts of an Access form

  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
Hello all,

I have a survey that is going to be passed are to the public. The
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/information-technology/13889-taking-word-form-using-fill-parts.html
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
Survey was created in Word 2003 using form fields and is protected. I
have also created an Access form with the same questions and fields as
the word. What I need to know is, is it possible to take the
information from the Word form and use it as an entry into the Access
form? Will we have to use data entry (A person manually putting in the
data)? I know that this can be done using Excel and Bookmarks that link
them together. Is there a similar method in Access?

Thanks,
~Amanda~




 
Do share your immediate thoughts or reactions on this issue? We value your views! Login Now! or Sign Up Today! to share your views with us.. Gurfateh!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 28-Jul-2006, 08:41 AM
Ken Sheridan's Avatar Ken Sheridan
Guest
 
Posts: n/a
   
   
RE: Taking a Word form and using it to fill in parts of an Access form

Amanda:

You would not insert the data directly into an Access form but into a table
on which a form can be based. Each Word document would be one row in the
table, so you could then analyze the data in Access. First you should create
a reference in your Access databse to the Microsoft Word Object Library which
you do by selecting Tools|References on the VBA menu bar while in your Access
database. In the dialogue scroll down until you find the reference then
check it.

To add the data to the table you can create a procedure in a standard module
in the databse. The following procedure illustrates a very simple example
where data from a Word document with two form fields is inserted into a table
called MyContacts with columns FirstName and LastName:

Sub GetWordForm(strPath As String)

On Error GoTo Err_Handler

Dim objWord As Object
Dim objDoc As Object
Dim fld As Word.FormField
Dim cmd As ADODB.Command
Dim frm As Form
Dim strSQL As String
Dim strValueList As String

' if Word open return reference to it
' else establish reference to it
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
Set objWord = CreateObject("Word.Application")
End If

AppActivate "Microsoft Word"
On Error GoTo Err_Handler

Set objDoc = objWord.Documents.Open(strPath)

' loop through form fields in document and build value list
For Each fld In objDoc.FormFields
strValueList = strValueList & ",""" & fld.Result & """"
Next fld
' remove leading comma
strValueList = Mid(strValueList, 2)

' insert row into table
strSQL = "INSERT INTO MyContacts(FirstName,LastName)" & _
"VALUES(" & strValueList & ")"
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
cmd.CommandText = strSQL
cmd.Execute

objDoc.Close
Set objDoc = Nothing
Set objWord = Nothing

Exit_here:
On Error GoTo 0
Exit Sub

Err_Handler:
MsgBox Err.Description & " (" & Err.Number & ")"
Resume Exit_here

End Sub

You'd call it by passing the path to the Word document to the procedure, e.g.

GetWordForm "F:\SomeFolder\SomeSubFolder\SomeDocument.doc"

You could do this in the Click event procedure of a button on a form say.
If you do it with a buton on a form bound to the table you can add the
following line to the procedure before the Exit Here: label:

Me.Requery

Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
This would requery the form so it includes the new record in its underlying
recordset.

You would not hard-code the path of course in reality, but get it from
somewhere as a variable. Opening a common dialog to browse to the file would
be the obvious solution. I use Bill Wilson's freely available
BrowseForFileClass class module, which can be downloaded from:

http://community.netscape.com/n/pfx/...g=ws-msdevapps

Ken Sheridan
Stafford, England

"AmandaH" wrote:

> Hello all,
>
> I have a survey that is going to be passed are to the public. The
> Survey was created in Word 2003 using form fields and is protected. I
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
> have also created an Access form with the same questions and fields as
> the word. What I need to know is, is it possible to take the
> information from the Word form and use it as an entry into the Access
> form? Will we have to use data entry (A person manually putting in the
> data)? I know that this can be done using Excel and Bookmarks that link
> them together. Is there a similar method in Access?
>
> Thanks,
> ~Amanda~
>
>


Reply With Quote
  #3 (permalink)  
Old 28-Jul-2006, 08:41 AM
AmandaH's Avatar AmandaH
Guest
 
Posts: n/a
   
   
Re: Taking a Word form and using it to fill in parts of an Access form

WOW thanks for that I am sure that it is going to work, except for:

Dim cmd As ADODB.Command

I get an error when I try to compile this line of code. It says
"user-defined-type not define" any ideas?

Reply With Quote
  #4 (permalink)  
Old 28-Jul-2006, 08:41 AM
Ken Sheridan's Avatar Ken Sheridan
Guest
 
Posts: n/a
   
   
Re: Taking a Word form and using it to fill in parts of an Access

Amanda:

It sounds like you don't have a reference to the ADO object library. Select
Tools|References on the VBA menu bar and scroll down to the Microsoft ActiveX
Data Objects Library. Check it and exit the dialogue. If you still have
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
problems I can let you have an amended version of the code using DAO which
was the default data access technology in Access before Access 2000, but can
still be used with later versions.

"AmandaH" wrote:

> WOW thanks for that I am sure that it is going to work, except for:
>
> Dim cmd As ADODB.Command
>
> I get an error when I try to compile this line of code. It says
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
> "user-defined-type not define" any ideas?
>
>


Reply With Quote
  #5 (permalink)  
Old 28-Jul-2006, 08:42 AM
Ken Sheridan's Avatar Ken Sheridan
Guest
 
Posts: n/a
   
   
Re: Taking a Word form and using it to fill in parts of an Access

Amanda:

One other thing I should have mentioned is that the code I sent you assumes
all the fields in the table which are being filled with data from the form
fields are of text data type. This is why each value in the value list is
wrapped in quotes. If the fields being filled were of mixed data types, some
text, some numbers , some dates say, then it would be necessary to amend the
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
code to take account of this. Rather than simply building a uniform value
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
list you'd need to build one where the delimiters for each field were of the
right type for the fields data type, quotes for text, # signs for dates and
none for numbers.

Ken Sheridan
Stafford, England

"AmandaH" wrote:

> WOW thanks for that I am sure that it is going to work, except for:
>
> Dim cmd As ADODB.Command
>
> I get an error when I try to compile this line of code. It says
> "user-defined-type not define" any ideas?
>
>


Reply With Quote
  #6 (permalink)  
Old 28-Jul-2006, 08:42 AM
AmandaH's Avatar AmandaH
Guest
 
Posts: n/a
   
   
Re: Taking a Word form and using it to fill in parts of an Access


Ken Sheridan wrote:
> Amanda:
>
> One other thing I should have mentioned is that the code I sent you assumes
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
> all the fields in the table which are being filled with data from the form
> fields are of text data type. This is why each value in the value list is
> wrapped in quotes. If the fields being filled were of mixed data types, some
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
> text, some numbers , some dates say, then it would be necessary to amend the
> code to take account of this. Rather than simply building a uniform value
> list you'd need to build one where the delimiters for each field were of the
> right type for the fields data type, quotes for text, # signs for dates and
> none for numbers.
>
> Ken Sheridan
> Stafford, England
>


How would a statments like that work?

Reply With Quote
  #7 (permalink)  
Old 28-Jul-2006, 08:42 AM
AmandaH's Avatar AmandaH
Guest
 
Posts: n/a
   
   
Re: Taking a Word form and using it to fill in parts of an Access


Ken Sheridan wrote:
> Amanda:
>
> One other thing I should have mentioned is that the code I sent you assumes
> all the fields in the table which are being filled with data from the form
> fields are of text data type. This is why each value in the value list is
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
> wrapped in quotes. If the fields being filled were of mixed data types, some
> text, some numbers , some dates say, then it would be necessary to amend the
> code to take account of this. Rather than simply building a uniform value
> list you'd need to build one where the delimiters for each field were of the
> right type for the fields data type, quotes for text, # signs for dates and
> none for numbers.
>
> Ken Sheridan
> Stafford, England
>


How would a statments like that work? What would it look like

Reply With Quote
  #8 (permalink)  
Old 28-Jul-2006, 08:42 AM
Ken Sheridan's Avatar Ken Sheridan
Guest
 
Posts: n/a
   
   
Re: Taking a Word form and using it to fill in parts of an Access

  Donate Today!  
Amanda:

As you are dealing with the same set of form fields and the same table each
time you will know the number of columns in the table and data type of each
one, so as you loop through the FormFields collection of the Word Document
you can increment an integer variable n. You can then examine the value of n
each time and wrap the value in the appropriate delimiters. Extending my
example so that the document has 4 form fields and the table has 4 columns
FirstName, LastName, DateOfBirth and Salary the first two are text data type,
the third date/time and the last a number, so the code would be amended like
so:

Sub GetWordForm(strPath As String)

On Error GoTo Err_Handler

Dim objWord As Object
Dim objDoc As Object
Dim fld As Word.FormField
Dim cmd As ADODB.Command
Dim frm As Form
Dim strSQL As String
Dim strValueList As String
Dim n As Integer

' if Word open return reference to it
' else establish reference to it
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
Set objWord = CreateObject("Word.Application")
End If

AppActivate "Microsoft Word"
On Error GoTo Err_Handler

Set objDoc = objWord.Documents.Open(strPath)

' loop through form fields in document and build value list
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
For Each fld In objDoc.FormFields
n = n + 1
Select Case n
Case 1, 2 ' text field so delimit with quotes
strValueList = strValueList & ",""" & fld.Result & """"
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13889
Case 3 ' date field so delimit with hashes and
' format date in US short date format
strValueList = strValueList & ",#" & _
Format(fld.Result, "mm/dd/yyyy") & "#"
Case 4 ' number field so no delimiters
strValueList = strValueList & "," & fld.Result
End Select
Next fld
' remove leading comma
strValueList = Mid(strValueList, 2)

' insert row into table
strSQL = "INSERT INTO MyContacts(FirstName,LastName, DateOfBirth,
Salary)" & _
"VALUES(" & strValueList & ")"
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
cmd.CommandText = strSQL
cmd.Execute

objDoc.Close
Set objDoc = Nothing
Set objWord = Nothing

Exit_here:
On Error GoTo 0
Exit Sub

Err_Handler:
MsgBox Err.Description & " (" & Err.Number & ")"
Resume Exit_here

End Sub

Note that the date is also formatted. This is because date literals in
Access must be in US date format or otherwise internationally unambiguous.
This is important to us Yurpeans, who unlike Mercans, use dd/mm/yyyy as our
standard short date format, so without formatting Access would interpret 4
July here as 7 April. For use with US formatted dates the formatting is not
actually necessary, but it does no harm and it internationalizes the
application if you leave it in.

By looping through the FormFields collection in order it is necessary for
the columns in the column list in the SQL statement to be in the same order
of course.

Ken Sheridan
Stafford, England

"AmandaH" wrote:
>
> How would a statments like that work? What would it look like
>
>


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

» Gurbani Jukebox
Listen to Gurbani while surfing SPN!
» Active Discussions
sikhism Who is "Mohan"?
Today 08:46 AM
22 Replies, 335 Views
sikhism How important is Matha...
Today 08:12 AM
59 Replies, 1,038 Views
sikhism need urgent advice.......
Today 06:46 AM
6 Replies, 81 Views
sikhism ਨਾਮਾ
Today 06:37 AM
2 Replies, 53 Views
sikhism Sikh Diamonds Video...
Today 04:23 AM
6 Replies, 116 Views
sikhism Are Creator and Creation...
Today 01:30 AM
44 Replies, 2,837 Views
sikhism Herman Hesse,...
Today 00:54 AM
13 Replies, 229 Views
sikhism On a Scale of Most...
Yesterday 21:42 PM
30 Replies, 1,277 Views
sikhism I became victim by...
Yesterday 19:50 PM
0 Replies, 44 Views
sikhism Sikh Books downloads
Yesterday 15:39 PM
2 Replies, 66 Views
sikhism Salok Sheikh Farid ji...
Yesterday 09:35 AM
0 Replies, 47 Views
sikhism In Punjab, three farmers...
Yesterday 05:36 AM
0 Replies, 49 Views
sikhism Supernatural Sikhs, what...
Yesterday 03:45 AM
19 Replies, 414 Views
sikhism Sukhmani Sahib Astpadi...
26-May-2012 22:57 PM
0 Replies, 51 Views
Do You Think You Are...
26-May-2012 09:59 AM
94 Replies, 8,258 Views
» Books You Should Read...
Powered by vBadvanced CMPS v3.2.2

All times are GMT +6.5. The time now is 09:46 AM.
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.2 Copyright © 2004-12, All Rights Reserved. Sikh Philosophy Network


Page generated in 0.43814 seconds with 30 queries