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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Time Error

Status
Not open for further replies.

ptrifile

Technical User
Aug 10, 2004
457
US
Can someone help me with this error. I am getting the error "Runtime error 13 Type mismatch". I am using the following code to get an average (being called from a button)...

Code:
Private Sub Command85_Click()
Dim i, numQ, total, avg As Single
Dim question As String

numQ = 0
total = 0

For i = 1 To 15
   question = "question" & i
   If Not IsNull(Me(question)) Then
   
   
      numQ = numQ + 1
      total = total + Me(question)
   End If
Next i

avg = total / numQ

Me!average = avg


End Sub

Any help or suggestion is welcome! thanks in advance

Paul
 
[!]I am getting the error "Runtime error 13 Type mismatch"[/i]
On which line ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Paul,
Do you realize that in this line
Code:
Dim i, numQ, total, avg As Single
only avg is Single? The other variables are created as Variants.

This code creates them all as Single:
Code:
Dim i as Single, numQ Single, total Single, avg As Single

Also avg is a reserved word and should not be used as a memory variable name. See Allen Browne's list of Problem names and reserved words in Access. A good naming convention typically avoids this type of issue.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top