Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Storing data from word doc to database and test word doc

Storing data from word doc to database and test word doc

Storing data from word doc to database and test word doc

Hi all,
I'm trying to store scattered text data from several word docs to database MS Access and into test word document but at the end there is no data in database or even in test word document. While Compiling Project I got Compile error Wrong number of arguments or invalid property assigment at line .Cells(.Rows.Count, 1) = sDTE.
Also I would like to save into a MS access table those Strings as Numbers so if You know how.... Thank You very much for any help.
Here is code from macro :

Sub ExtractData2()
    Dim sDTE As String
    Dim sSubject As String
    Dim strFileName As String
    Dim strPath As String
    Dim FileArray() As String
    Dim i As Long
    Dim vConnection As ADODB.Connection
    Dim vRecordSet As ADODB.Recordset
    Dim oDoc As Document
    Dim Datadoc As Document
    Dim fDialog As FileDialog
    Dim Rng As Range
    Dim NumRows As Integer
    Set vConnection = New ADODB.Connection
    Set vRecordSet = New ADODB.Recordset
    Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
     'Pick the folder with the letters
    With fDialog
        .Title = "Odaberite direktorij s zahtjevima i kliknite na gumb OK"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then
            MsgBox "Cancelled By User"
            Exit Sub
        End If
        strPath = fDialog.SelectedItems.Item(1)
        If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
    End With
    strFileName = Dir$(strPath & "*.doc")
    ReDim FileArray(1 To 1000) 'A number larger the expected number of replies
    Do While strFileName <> ""
        i = i + 1
        FileArray(i) = strFileName
         'Get the next file name
        strFileName = Dir$
     'Resize and preserve the array
    ReDim Preserve FileArray(1 To i)
    Application.ScreenUpdating = False
     'Provide connection string for data using Jet Provider for Access database
    vConnection.ConnectionString = "data source=C:\MagRad\Baza.mdb;" & _
    vRecordSet.Open "MyTable", vConnection, adOpenKeyset, adLockOptimistic
     'Retrieve the data
    vConnection.Execute "DELETE * FROM MyTable"
     'Assign the name of the document to take the data
    Set Datadoc = Documents.Open("C:\MagRad\Rez.doc")
     'Open the letters in turn
    While strFileName <> ""
        Set oDoc = Documents.Open(strPath & strFileName)
         'Find the DTE text
        Set Rng = oDoc.Range
        With Rng.Find 'find the first string
            Do While .Execute(Findtext:="DTE/*^13", _
                MatchWildcards:=True, _
                Wrap:=wdFindStop, Forward:=True) = True
                 'Assign the found text to a variable and
                 'chop off the last character - '¶'
                Rng.SetRange 0, Len(Rng) - 1
                sDTE = Rng.Text
        End With
        Set Rng = oDoc.Range 'Redefine range after find
        With Rng.Find 'find the second string
            Do While .Execute(Findtext:="Subject :*^13", _
                MatchWildcards:=True, _
                Wrap:=wdFindStop, Forward:=True) = True
                 'Assign the second string to a variable and chop off
                 'the the leading text and last character.
                Rng.SetRange 9, Len(Rng) - 1
                sSubject = Rng.Text
        End With
         'Switch to the data document and add the content of
         'the variables to the blank row of the table
        If sDTE <> "" Then vRecordSet("DTE") = sDTE
        If sSubject <> "" Then vRecordSet("Subject") = sSubject
        With Datadoc.Tables(1).Range
            .Cells(.Rows.Count, 1) = sDTE
            .Cells(.Rows.Count, 2) = sSubject
        End With
         'Close the letter without saving
        oDoc.Close SaveChanges:=wdDoNotSaveChanges
        Set oDoc = Nothing
        strFileName = Dir$()
    Set vRecordSet = Nothing
    Set vConnection = Nothing
    Application.ScreenUpdating = True
End Sub  

RE: Storing data from word doc to database and test word doc

This question is better answered on Tek-Tips.com... this forum is more about engineering of the languages themselves (contrary to many postings that end up residing here).

Dan - Owner

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


eBook - Manufacturing the Cars of Tomorrow
In this ebook, we'll explore how additive manufacturing is going to transform the way cars are made. This includes commentary from thought leaders such as Ford's CTO, Ken Washington, Customer case studies of ways 3D printing is being used today, and a variety of part examples where 3D printing is already impacting how automobiles are made. Download Now
White Paper - Smart Manufacturing for Semiconductor
New technologies and approaches present great opportunities for semiconductor manufacturers to achieve high levels of innovation, yield and improvement. This white paper explores some of these cutting-edge technologies and how they can be applied effectively in the semiconductor industry. Read about how Smart Manufacturing is transforming the semiconductor industry. Download Now
White Paper - Analysis and Simulation in Aircraft Structure Certification
Organizations using simulation and analysis tools effectively see the benefits in their ability to achieve certification faster and with drastically less total cost than those who do not maximize these tools. Read this White Paper to learn about how digital tools such as analysis and simulation help in aircraft structure certification. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close