rjudge
03-01-2013, 10:37 AM
I won't admit to how long I have researched this and how many attempts I have tried to get a loop through textboxes to work. Clearly I am an idiot even for a newbie.
ActiveDocument.txtQuestion1.Value = value in the first textbox.
Yes, I know an array is silly since ideally I would just loop through the textboxes without having to store the values in an array since they are already in a collection. However, if you help me with the code below, I believe even I can do the rest.
This is what I have in code that solves my problem, but is clearly silly:
Dim stdAnsArray(numQuestions) As Variant
stdAnsArray(0) = ActiveDocument.txtQuestion1.Value
stdAnsArray(1) = ActiveDocument.txtQuestion2.Value
stdAnsArray(2) = ActiveDocument.txtQuestion3.Value
stdAnsArray(3) = ActiveDocument.txtQuestion4.Value
stdAnsArray(4) = ActiveDocument.txtQuestion5.Value
stdAnsArray(5) = ActiveDocument.txtQuestion6.Value
stdAnsArray(6) = ActiveDocument.txtQuestion7.Value
As mentioned I have tried various other coding such as:
For k = 0 to numQuestions-1
stdAnsArray(k) = "txtQuestion" & k+1.Value
Next
But this does not work. I have tried adding ActiveDocument in front of "txtQuestion" and that did not work.
Fortunately I am already bald.
Any help greatly appreciated.
ActiveDocument.txtQuestion1.Value = value in the first textbox.
Yes, I know an array is silly since ideally I would just loop through the textboxes without having to store the values in an array since they are already in a collection. However, if you help me with the code below, I believe even I can do the rest.
This is what I have in code that solves my problem, but is clearly silly:
Dim stdAnsArray(numQuestions) As Variant
stdAnsArray(0) = ActiveDocument.txtQuestion1.Value
stdAnsArray(1) = ActiveDocument.txtQuestion2.Value
stdAnsArray(2) = ActiveDocument.txtQuestion3.Value
stdAnsArray(3) = ActiveDocument.txtQuestion4.Value
stdAnsArray(4) = ActiveDocument.txtQuestion5.Value
stdAnsArray(5) = ActiveDocument.txtQuestion6.Value
stdAnsArray(6) = ActiveDocument.txtQuestion7.Value
As mentioned I have tried various other coding such as:
For k = 0 to numQuestions-1
stdAnsArray(k) = "txtQuestion" & k+1.Value
Next
But this does not work. I have tried adding ActiveDocument in front of "txtQuestion" and that did not work.
Fortunately I am already bald.
Any help greatly appreciated.