Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Reading MS Word & Passing Value

Posted on 2004-11-04
6
Medium Priority
?
171 Views
Last Modified: 2010-05-02
Hi - have a question about reading an MS Word file that has 16 field values (will expand to 356) and them I'm going to add each value into an MS Access DB.

Here's what I've done:
1.  Declared values 1 - 16 as: Public strQ1a, strQ1b, strQ1c, strQ1t As String
2.  Written the following code that opens MS Word file and reads the data.

Here's my problem:
1.  strA part of the code works just as I wanted.
2.  I want to loop through an assign a value for each strQ?a value,

I could add "strQ1a = doc.FormFields("G1a").Result" for each row value that would get really long.  Imagine creating 356 lines.

Any suggestions?

'------------------------------------------------------------------------------------------------------
Function ReadWord()
On Error Resume Next

    Dim appWord As Word.Application
    Dim doc As Word.Document
    Dim i As Integer
    Dim strA, strB, strC, strT As String
    Dim strQVA, strQVB, strQVC, strQVT As String
    Dim strAQ, strBQ, strCQ, strTQ As String

    i = 1
   
    Set appWord = CreateObject("Word.Application")

    Set doc = appWord.Documents.Open(strWordPath)
    strCounter = 0

    For i = 1 To 3
        strA = "G" & i & "a"
        strB = "G" & i & "b"
        strC = "G" & i & "c"
        strT = "G" & i & "t"

        strAQ = doc.FormFields(strA).Result
        Call ProgressBar
        strBQ = doc.FormFields(strB).Result
        Call ProgressBar
        strCQ = doc.FormFields(strC).Result
        Call ProgressBar
        strTQ = doc.FormFields(strT).Result
        Call ProgressBar

        strQVA = "strQ" & i & "a" & "=" & strAQ
        strQVB = "strQ" & i & "b" & "=" & strBQ
        strQVC = "strQ" & i & "c" & "=" & strCQ
        strQVT = "strQ" & i & "t" & "=" & strTQ

    Next i

    doc.Close
    appWord.Quit
End Function
'------------------------------------------------------------------------------------------------------
0
Comment
Question by:eciabattari
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12496311
Am i missing something here? Can't you just use an array?
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12496328
PS:
 Dim strA, strB, strC, strT As String
Does not create 4 strings, but 3 variants and one string. The correct syntax is:

 Dim strA  As String, strB  As String, strC As String, strT As String
0
 

Author Comment

by:eciabattari
ID: 12496363
Didn't think of using an array.  Really haven't done many, can you show me an example?

Thanks

P.S. I've corrected the other.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
fds_fatboy earned 2000 total points
ID: 12496452
Something like...

...
Dim strQA() As String
Const MAXROWS = 356' Or whatever
...
...
    Redim strQA(1 to MAXROWS)
    For i = 1 to MAXROWS
        strQA(i) = doc.FormFields("G" & i & "a").Result
    Next



0
 

Author Comment

by:eciabattari
ID: 12496535
Works perfect... thanks for the help.
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12496571
Why not use a 2 dimensional array?

Something like

...
Dim strQA() As String
Const MAXROWS As Long = 356' Or whatever
Dim Suffix() As String
Dim i As Long
Dim j as Long
...
...
    Suffix = Split(",a,b,c,t", ",")
    Redim strQ(1 to MAXROWS, 1 to 4)
    For i = 1 to MAXROWS
         For j = 1 to 4
            strQ(i,j) = doc.FormFields("G" & i & Suffix(j)).Result
         Next
    Next
...
...
...

So G1a will be stored in strQ(1,1), G3b will be stored in strQ(3,2), G5t in strQ(5,4) etc.


0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question