Reading MS Word & Passing Value

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
'------------------------------------------------------------------------------------------------------
eciabattariAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fds_fatboyCommented:
Am i missing something here? Can't you just use an array?
0
fds_fatboyCommented:
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
eciabattariAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

fds_fatboyCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eciabattariAuthor Commented:
Works perfect... thanks for the help.
0
fds_fatboyCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.