Subscript out of Range

A

A_Classic_Man

I have a Word form with bookmarks. I move the bookmarked data to an
Access database using code suggested by Doug Robbins. He suggested
using the code found at http://gregmaxey.mvps.org/Extract_Form_Data.htm.
The code was working great till a couple of days ago. All at once I
get the message "Run-Time error "9", Subscript out of range. The code
is hanging on "ReDim Preserve FileArray (1 To i).

I rebuilt Greg Maxey's Word form and the Access database and ran his
code and now I get the same error message.

My References are: VB for Apps, MS Word II Obj Library, OLE
Automation, MS Office II Obj Library, MS ActiveX Data Obj 2.8 Library,
and MS Scripting Runtime.

Can someone tell me what happened here?

Thanks in advance

Ron
 
J

Jean-Guy Marcil

A_Classic_Man said:
I have a Word form with bookmarks. I move the bookmarked data to an
Access database using code suggested by Doug Robbins. He suggested
using the code found at http://gregmaxey.mvps.org/Extract_Form_Data.htm.
The code was working great till a couple of days ago. All at once I
get the message "Run-Time error "9", Subscript out of range. The code
is hanging on "ReDim Preserve FileArray (1 To i).

When the code hangs, what is the value of i at that point?
What was the array size before your code attempts to ReDim it?
 
A

A_Classic_Man

When the code hangs, what is the value of i at that point?
What was the array size before your code attempts to ReDim it?

Arrays are new to me. I have tried to read up on them, but having
trouble understanding the code.
So how do I find the value of i and does the array size refer to the
total number of bookmarks that are to be moved?

I'm really lost here

Ron
 
J

Jean-Guy Marcil

A_Classic_Man said:
Arrays are new to me. I have tried to read up on them, but having
trouble understanding the code.
So how do I find the value of i and does the array size refer to the
total number of bookmarks that are to be moved?

You must have a line that says something like:
ReDim FileArray(1 To 15)

Then, before running the code, in the VBA editor window, do:
View menu > Locals Window

When you run the code, all the variables and objects will be listed in that
window.

When the code hangs, look at the value of "i".

Also, the following two sequences will generate the subscript out of range
error:

IF the ReDim lower value is different from the previous one:

Dim FileArray()

ReDim FileArray(0 To 15)

ReDim Preserve FileArray(1 To 10) '1 <> 0



Dim FileArray()

ReDim FileArray(15) 'Default lower value is 0

ReDim Preserve FileArray(1 To 10) '1 <> 0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top