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!

Word97 "ActiveDocument.FormFields" problem

Status
Not open for further replies.

Anthony904

IS-IT--Management
Jul 15, 2004
153
US
Hi,

I have a word97 document that has some form fields. Instead of having users come in and click on each individual formfield to enter data. I created a userform.

This userform has some fields that the users enters in a single data and thats fine. Now I have some fields that require them to enter feet and inches.

These feet and inches calculate into levels. (shown in function levels below) I want the result to be displayed on my form field in my document.

From the code above I'm getting an error:

Compile Error:

Wrong number of arguments or invalid property assignment.

Any ideas?
Thanks!

Code:
Private Sub CommandButton1_Click()
FeetnInches
End Sub

Code:
Function Levels(iLevel As Integer) As Double
Select Case iFeet
    Case 0
        Select Case iInches
            Case 0
                Levels = 0
            Case 1
                Levels = 1
            Case 2
                Levels = 2
            Case 3
                Levels = 3
            Case 4
                Levels = 5
         End Select
    Case 1
        Select Case iInches
            Case 0
                Levels = 14
            Case 1
                Levels = 15
            Case 2
                Levels = 16
            Case 3
                Levels = 17
            Case 4
                Levels = 18
         End Select
    Case 2
        Select Case iInches
            Case 0
                Levels = 28
            Case 1
                Levels = 29
            Case 2
                Levels = 30
            Case 3
                Levels = 31
            Case 4
                Levels = 32
         End Select
    Case "" 'Blank formfield
        Levels = 0
    Case Else   ' Other value
        Levels = 0
End Select
End Function

Code:
Function FeetnInches()
'Retrieves Feet and Inches from lookup table(above)
On Error GoTo Label
    ActiveDocument.FormFields("txtResult").Result = Levels(ActiveDocument.FormFields("txtFeet").Result, ActiveDocument.FormFields("txtInches").Result)
Label:
Resume Next
End Function
txtResult form field on document
txtFeet and txtInches are on userform: frmFtNinch

Thanks~!
 
Your Levels function is declared with only one parameter (iLevel) and you call it with two.
I guess the function should be declared like this:
Function Levels(iFeet, iInches As Integer) As Double

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ok that seem to get rid of the error.. But the function doesn't seem to be working still..

Also, I have a correction to my question..

Instead of displaying the calculated level on the document. I need for it to be displayed on the userform.

Here's an example of what the user does when he enters data.

1. User opens word document. Clicks a button that opens up a userform (frmInput) to enter data.

2. Users enters data.. when users tabs over the field that requires feet and inches, a form pops up (frmFtNinch)

3. Users enters in feet and inches hits a <calulate> button. The result should be displayed on form frmInput (field name: txtResult)


Once the data is on frmInput I have some code that moves that into the document.

My problem is .. it's not displaying the level on frmInput. (it's not displaying anywhere)

Thanks for your help and response!



 
Comment out the On Error GoTo Label instruction to see if you get run time errors.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ok.. I'm getting this error.

run-Time error:

the requested member of the collection does not exist.
 
I guess you have a problem with the ActiveDocument.FormFields collection ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Am I suppose to specify which form each value goes to?

if so, how?

thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top