Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOT file won't run in word 97 2

Status
Not open for further replies.

Anthony904

IS-IT--Management
Jul 15, 2004
153
US
I have a word template with some macros that move data from one data form field to another with a button...

When I run this .dot file in word 2000 it works fine.. When I try to run it in Word 97.. I get the error below..

Error:

Run-Time Error '5941':
The requested member of the collection does not exist.

The error points to is the function I use to move data..


Code:
Function mShift(s1 As String, s2 As String, d1 As String, d2 As String)
'This Function moves field s1,s2 to fields d1,d2
FormFields(d1).Result = FormFields(s1).Result
FormFields(d2).Result = FormFields(s2).Result
FormFields(s1).TextInput.Clear
FormFields(s2).TextInput.Clear
End Function


Is there something wrong with this code? If so, how can I fix this?

Thanks
 
Hi Anthony904,

I've just had a play with this on 97 and the problem is declaring your arguments as Strings. If you declare them either explicitly or implicitly as Variant, the problem goes away.

This (which is what you have) fails in 97 (but works in 2003 - I haven't tested on 2000)
Code:
Function mShift(s1 As String, s2 As String, d1 As String, d2 As String)

But this works in 97 (and 2K3)
Code:
[blue]Function mShift(s1 As Variant, s2 As Variant, d1 As Variant, d2 As Variant)[/blue]

As does this
Code:
[blue]Function mShift(s1, s2, d1, d2)[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Gerry,

I changed the names and same error message. I have it as a function because.. I have different lookup fields for different fields.. So the lookup case statements shown in the example I put out are for the first couple of fields.. I have over 50 fields that require different lookups..

Each function would be a different lookup table. Then I run all the functions under the Cal_Button.

Thats the only way I saw to do that.. if you have a suggestion I'm open...


Tony,

Thanks.. I will try your suggestion and get back with you..

THANKS to the both of you!

 
Sorry took so long to respond..

But it seems that the declaration as variants seem to work!

Why is that?

Thanks to the both of you for your time and effort!
 
I can only guess!

There are small differences (normally only significant when interfacing to non-VBA environments) between the way different variable types are held in memory. The index into a collection can be either a name or a number so somewhere under the covers there are checks to be made and conversions to be done - I don't know exactly what or how or where. For some reason it appears that these aren't properly done in 97 (VBA 5) unless the variables are Variant whilst they are properly done in later versions of Word (with VBA version 6) regardless of variable type.

Sorry I can't elucidate further.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top