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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

MS-Word Visual Basic Array ?

Keep this in mind as you read:  I do not have the full version of visual basic; I'm working with the MS-Word version.  

My question is this:  How can I bring an array's information from one form to another?  I've tried to declare it under DELCARATIONS but it still won't come through.

Here is a bit of the code I'm trying.

For fn = 1 To frmFatherNumberBar.scrlFatherNumber.Value
Selection.InsertAfter fathername(fn) + ";"
Next fn

frmfathernumberbar is a seperate form from the one I'm on, and scrlfathernumber.value is a scroll bar.
I need the current form to pull "fathername(1)", etc.. from the form frmFatherNumberBar.

Any ideas how to do this?

-rick detroit
0
saksafon2
Asked:
saksafon2
1 Solution
 
wesleystewartCommented:
Are you sure the syntax is correct:

Selection.InsertAfter fathername(fn) + ";"

It might be:

Selection.InsertAfter fathername(fn) ";"

without the "+" operator.  I'll have to tinker with it a little bit and see.

Wes
0
 
saksafon2Author Commented:
I've used the + ";" syntax a few times.  For this example we could even leave the + ";" out.
The problem it's having is just getting the array over.  Meh!  It's frustrating.

lol
rick
0
 
Brendt HessSenior DBACommented:
First, when you declare fathername(), make it a PUBLIC variable, e.g.:

PUBLIC fathername() as String

Then, when you reference the variable, make sure that you reference the form as well:

Selection.InsertAfter frmFatherNumberBar.fathername(fn) + ";"

That should do it.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
wesleystewartCommented:
If you put a stop on this line:

For fn = 1 To frmFatherNumberBar.scrlFatherNumber.Value

(click on te gray bar to the left of this line of code) then the code will stop before it executes that line.  When it does, hit ctrl+G and the immediate window will pop up.  When it does, paste this in and hit return:

? frmFatherNumberBar.scrlFatherNumber.Value

The value in your scroll bar should pop up.  If it doesn't, then we need to start somewhere else.

Wes
0
 
saksafon2Author Commented:
Meh!  

Bhess1, the idea is perfect and it's exactly what I'm looking for except the computer is giving me two different errors:

First, when I "PUBLIC" the variable in general declerations, it states that "Constants, fixed-length strings, arrays, and DECLARE statements not allowed as public members of object modules".

I placed the declerations actually in the code and it compiled, but when I got to the 2nd form that needs to call it, it states that it still can't find the array from the other form.  Any ideas?

rick
0
 
wesleystewartCommented:
Can you move this code into a general module and get it out of the form module?  Then you can use all those neat words like constant, public, etc.

You might have to add some syntax to take care of object references(like your form and document) but I think that would be the best way.

Wes
0
 
saksafon2Author Commented:
How do I do that and how would I be able to call it up from the form?

rick
0
 
wesleystewartCommented:
Absolutely.

From the Word IDE, click >>Insert>>Module and a new module window will pop up.  You can create a new subprocedure by typing Sub MyProc() and hitting Enter.

Then your code will go in MyProc.  Use a button on your form or another event (form close, etc) and call MyProc from within the event.

How are you calling the code now?  It shouldn't be much different.

Wes
0
 
cquinnCommented:
Refer to the array (which I assume is declared in frmfathernumberbar) using the explicit reference as below:
 
frmFatherNumberbar.fathername(fn)


P.S.

Use the ampersand (&) to concatenate strings - if you concatenate with the plus sign (+) and any of the things you are concatenating is null, the whole string ends up as null!

0
 
saksafon2Author Commented:
It says "PUBLIC" is an invalid attribute inside a sub-procedure.
I made one and copied the info in and it says it doesn't want to work.

Go fig.  MEH!

rick
0
 
saksafon2Author Commented:
Adjusted points to 60
0
 
wesleystewartCommented:
public is invalid in a subprocedure.  It goes in the declarations section at the top of the module, NOT inside the procedure.

This makes it available to the whole project.

Wes
0
 
saksafon2Author Commented:
The module idea was great.  I placed both sets of procedures that need the variables in a seperate module with different procedures and it's going to call up and work fine.  Thanks for the help again.
Your savin' my life here.

-rick, detroit
0
 
wesleystewartCommented:
I'm happy to help.  If you're going to be doing a lot of programming in Word, I suggest the following two books:

http://www.oreilly.com/catalog/writewordmacro/
http://www.oreilly.com/catalog/pwomodel/noframes.html

If you get them from Amazon I think they are about $20 each.  I don't work for O'Reilly or anything like that, I just think their books are the best no-nonsense reference texts on the market.  They manage to get as much good stuff into 500 or 600 pages as Sybex and the others get into 1200 to 1500 pages.

VBA, as it is implemented in Word, is the exact same language engine (VBA332.dll) found in VB, so programming in word is a great step towards progarmming in VB.

Wes
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now