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 wOOdy-Soft 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
 
Probably it is not backward compatible!


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
How can I get it to run in word 97 and 2000?

Many users have one or the other.. upgrade all to 2000 is not an option now..

Thanks for the response..
 
Design it/save it in 97.
That should eliminate compatability issues.

Tired of waiting for an answer? Try asking better questions. See: faq222-2244
 
To elaborate, Word 97 came with VB 5.0 and 2k came with 6.0...this may be the root of the problem (i.e. forward vs. backwards compatability).

Tired of waiting for an answer? Try asking better questions. See: faq222-2244
 
You can try recording a macro dealing with formfields in 97. Check out the syntax. There could be some differences that you could adjust.

I have to ask about this function though.

It takes in strings as parameters...then uses those strings as the SAME names of the formfields. This seems very odd to me. Although I could very easily be missing something obvious. Could you tell me why you are doing this? Also, is there a particular reason you are making this a Function rather than a Sub?

Gerry
See my Paintings and Sculpture
 
Thanks for the info..

I have both 97 and 2000 on my machine.. and it jumps to 2000 when I open word.. I coulda sworn I wrote it in 97.. Ahh! ohh well

I'll redesign in 97..

Thanks!
 
A thought - will the 2000 users automatically update the 97 template when they open it? Will they get a box asking if they want to convert? Can this be protected against?

Tim

[blue]_____________________________________________________
If you need immediate assistance, please raise your hand.
If you are outside of Raleigh, raise your hand and say
[/blue] [red]Ooh! Ooh![/red]
 
fumei,

heres a summary of wat the template does.

This form is basically a log file.. A user comes in each day and puts some numbers in a field. When done, they hit a button I created that pulls in a number according to the number they entered.

Now the user hits the save button and the data that the user entered today moves to another field on the form (the mshift function) and the form is saved and moved to a folder with todays date as the name.

Now as the we enter the next day.. the user pulls up the form that was last used (according to date) enters in todays data and compares that with the data last used.

When complete the user hits save again.. and that would clobber old data moving today's data into the appropiate form field. .. and a file is created with todays date and moved into a folder.... etc...

Silent,

If convert, would user still be able to run? if so then this is ok.


All,

I created my word app. in 97 and I'm still getting error 5941..

Did I do something wrong?

thanks

 
If VBA is saying that the item does not exist, then....it doesn't, at least by the name refered to. The reason for that is still unclear to me, because I am unclear on exactly the process going on. There is something going on with the saves that I am not getting.

What I DO know, is that if you are doing any copies of the formfields themselves, then they do not carry a name forward. Which means even those copied formfield exists, and ARE part of the collection, they have no name. So calling them by name will return that error. Are you copying them?



Gerry
See my Paintings and Sculpture
 
Gerry,

When I run the report in Word 2000.. the form runs fine.. but in word 97 I get a problem.. I don't understand why..

Another problem I find that may be related to the first is that..

I had some code (someone helped with) that would "move" data from one field to another when I clicked a button.

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

Function mShift2(a1 As String, b1 As String)
'This function moves field s1 to d1
FormFields(b1).Result = FormFields(a1).Result
FormFields(a1).TextInput.Clear
End Function
Private Sub Button_Save_Click()

'Moves fields text1,text2 to text3, text4.. etc.. with the function mShift etc..
mShift "Text1", "Text2", "Text3", "Text4"
mShift "Text5", "Text6", "Text7", "Text8"

'Moves fields Text30 to Text 29 with function mShift2 etc..
mShift2 "Text30", "Text29"
mShift2 "Text32", "Text31"

ThisDocument.Save

Now I have other code behind this button that saves the document (with todays date as the name) and strips out the button (printing purposes)

When I remove the code that move (shift) data from one field to another .. the form runs fine..

Is there something wrong with the code? As far as if the code copies I'm not sure. That's the code I was helped with and it runs fine without it, but I still need to move data from one field to another...

Thanks..

and sorry for the long post..
 
No apologies are need re: long posts. We would rather have a full explanation that is undertsanable, than a terse one one that we have to ask repeated questions about.

OK.

Word 97 does have a problem with emptying formfields. This was fixed in 2000. I would suggest you do NOT use TextInput.Clear with '97, as this is the equivalent to resetting.

Try making the .Result = "", rather than TextInput.Clear.

Gerry
See my Paintings and Sculpture
 
I'm having a little trouble with trying to set the field to blank..

I tried:

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).Result = ""
FormFields(s2).Result = ""
End Function

and I tried

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) = ""
FormFields(s2) = ""
End Function

Thanks for the help!
 
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).Result = ""
FormFields(s2).Result = ""
End Function

Sub MoveEm()
mShift "s1", "s2", "d1", "d2"
End Sub

works fine for me.

Do you have your formfields set to Calculate on exit? If not, turn 'em on.

Gerry
See my Paintings and Sculpture
 
Gerry,

Sorry took awhile to get back to you.. so many deadlines.. but back to this document..

I tried the code you suggested.. and made sure the Field settings were check with Calculate on exit.

I am still getting the same error:

run-time error: 5941
The requested member of the collection does not exist.


Whenever I run the code in Word 2000 everything works fine.. but when i go to try it in Word 97.. that's when the error comes up.

Any ideas?

Thanks!
 
I do not have 2000, so it is impossible for me to test. Try running some formfield.result code in 2000 and get some proper syntax.

As an side comment. You can reduce a lot of your Select case code:

Your code:
Code:
Select Case ActiveDocument.FormFields("Text1").Result
    Case 0
        ActiveDocument.FormFields("Text2").Result = 5
    Case 1
        ActiveDocument.FormFields("Text2").Result = 5.16
    Case 2
        ActiveDocument.FormFields("Text2").Result = 5.32
    Case 3
        ActiveDocument.FormFields("Text2").Result = 5.48
    Case 4
        ActiveDocument.FormFields("Text2").Result = 5.64
    Case 5
        ActiveDocument.FormFields("Text2").Result = 5.8
    Case 6
        ActiveDocument.FormFields("Text2").Result = 5.98
    Case 7
        ActiveDocument.FormFields("Text2").Result = 6.16
    Case 8
        ActiveDocument.FormFields("Text2").Result = 6.34
    Case 9
        ActiveDocument.FormFields("Text2").Result = 6.52
    Case 10
        ActiveDocument.FormFields("Text2").Result = 6.7
    Case 11
        ActiveDocument.FormFields("Text2").Result = 6.88
    Case 12
        ActiveDocument.FormFields("Text2").Result = 7.06
    Case 13
        ActiveDocument.FormFields("Text2").Result = 7.24
    Case 14
        ActiveDocument.FormFields("Text2").Result = 7.42
    Case 15
        ActiveDocument.FormFields("Text2").Result = 7.6
    Case 16
        ActiveDocument.FormFields("Text2").Result = 7.81
    Case 17
        ActiveDocument.FormFields("Text2").Result = 8.02
    Case 18
        ActiveDocument.FormFields("Text2").Result = 8.23
    Case 19
        ActiveDocument.FormFields("Text2").Result = 8.44
    Case 20
        ActiveDocument.FormFields("Text2").Result = 8.65
    Case 21
        ActiveDocument.FormFields("Text2").Result = 8.86
.....etc etc

An alternative:
Code:
Dim result As Integer
Dim i As Integer
result = ActiveDocument.FormFields("Text1").result
Select Case result
    Case 0 To 5
      For i = 0 To result
         ActiveDocument.FormFields("Text2").result = _
               5 + (result * 0.16)
      Next
    Case 6 To 15
        For i = 6 To result
           ActiveDocument.FormFields("Text2").result = _
               5.8 + ((result - 5) * 0.18)
        Next
    Case 16 To 21
         For i = 16 To result
            ActiveDocument.FormFields("Text2").result = _
               7.6 + ((result - 15) * 0.21)
         Next
....etc etc

This reduces the amount of parsing required and should run a bit faster. Especially as you have 100 Case statement. You can reduce this by 80%.

I am trying to find a copy of 2000 to test formfields on.

Gerry
See my Paintings and Sculpture
 
Gerry,

The problem occurs when I try to run the document in Word 97 not 2000. Word 2000 works fine.. but my users have Word 97.

You said you have word 97? I'm not sure why its running on your and not mines?


Also,

Thanks for the suggestion on the Case Statments.. I would have never thought to do that..

Thanks!
 
Sorry, I don't have 97 or 2000.

In any case, here are a couple of suggestions.

1. Change the names. I have no idea if there has been any movement of your formfields, but you are using default names. Say you have two formfields - Text1 and Text2. If Text1 is moved to AFTER Text2 it is automatically named Text2, and Text2 is automatically renamed Text1. Try it with explicitly named formfields. I do not think this is the problem, as you say it runs properly in other versions....but named them explicitly anyways.

2. What happens if you Step through it? Can you identify where the error occurs?

3. What happens if you add a On Error Resume Next?

4. Could you please confirm that the error is from the Lookup function? Still wondering why you have it as a function....

Gerry
See my Paintings and Sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top