×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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

(OP)
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$
    Loop
     '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;" & _
    "Provider=Microsoft.Jet.OLEDB.4.0;"
    vConnection.Open
    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
            .ClearFormatting
            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
            Loop
        End With
        Set Rng = oDoc.Range 'Redefine range after find
        With Rng.Find 'find the second string
            .ClearFormatting
            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
            Loop
        End With
         'Switch to the data document and add the content of
         'the variables to the blank row of the table
         'Datadoc.Activate
        Datadoc.Save
        If sDTE <> "" Then vRecordSet("DTE") = sDTE
        If sSubject <> "" Then vRecordSet("Subject") = sSubject
        vRecordSet.Update
        With Datadoc.Tables(1).Range
            .Rows.Add
            .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$()
    Wend
    vRecordSet.Close
    vConnection.Close
    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
http://www.Hi-TecDesigns.com

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


Resources

eBook - Integrating the Engineering Ecosystem
Aras Innovator provides multiple options for integrating data between systems, depending on the scenario. Utilizing the right approach to meet specific business requirements is vital. These needs range from authoring tools, federating data from various and dissimilar databases, and triggering processes and workflows. Download Now
Research Report - Simulation-Driven Design for SOLIDWORKS Users
In this engineering.com research report, we discuss the rising role of simulation and the paradigm shift commonly called the democratization of simulation. In particular, we focus on how SOLIDWORKS users can take advantage of simulation-driven design through two analysis tools: SOLIDWORKS Simulation and 3DEXPERIENCE WORKS. Download Now
White Paper - Industry 4.0 and the Future of Engineering Education
With industries becoming more automated, more tech-driven and more complex, engineers need to keep their skills and knowledge up to date in order to stay on top of this wave—and to be prepared for the Industry 4.0 future. The University of Cincinnati offers two online Master of Engineering degree programs designed specifically for practicing engineers. Download Now
eBook - The Design Gridlock Manifesto
In this eBook, you’ll learn 6 ways old CAD technology slows your company down and hear how design teams have put those problems to rest. “The Design Gridlock Manifesto” shares first-hand modern CAD experiences from 15 companies around the world. 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