Smart questions
Smart people
 Find A ForumFind An Expert
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Remember Me

Are you a
Computer / IT professional?
Join Tek-Tips now!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

#### Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site

#### Feedback

"...It's extraordinarily refreshing to see truly expert advice without having to wade through hipper than thou attitude..."

#### Geography

Where in the world do Tek-Tips members come from?

# Type Mismatch Using Function

 Forum Search FAQs Links Jobs Whitepapers MVPs
 MeldrethMan (TechnicalUser) 2 Aug 12 10:43

I'm calling this function from a form but am getting a type mismatch error. It works fine in the Immediate window eg ?Points(8,11,5,5) returns 2.

#### CODE -->

```Public Function Points(ShotAllowance As Byte, SI As Byte, Score As Byte, Par As Byte)

Dim Diff As Byte
Dim Netscore As Byte

If ShotAllowance > 18 Then
Netscore = IIf(SI > (ShotAllowance - 18), Score - 1, Score - 2)
Else
Netscore = IIf(SI > ShotAllowance, Score - 0, Score - 1)
End If

Diff = Netscore - Par

If Diff = -3 Then Points = 5
If Diff = -2 Then Points = 4
If Diff = -1 Then Points = 3
If Diff = 0 Then Points = 2
If Diff = 1 Then Points = 1
If Diff > 1 Then Points = 0

End Function ```

The subform contains the command button that calls the function, and two of its parameters. The other two parameters are in the frmComps. This is one of the calls, where Points1 is type Number/Byte

#### CODE -->

`Points1 = Points(ShotAllowance, [Forms]![frmComps].SI1, Score1, [Forms]![frmComps].[Par1]) `

I also get the error if using a test set of numbers as parameters instead of these references.

Any thoughts?
 MajP (TechnicalUser) 2 Aug 12 13:24
 Trye Points1 = Points(cbyte(ShotAllowance), cbyte([Forms]![frmComps].SI1), cbyte(Score1), cbyte([Forms]![frmComps].[Par1])) The forms reference will return a variant datatype that will not automatically cast to a byte.
 MeldrethMan (TechnicalUser) 2 Aug 12 15:01
 Thanks for taking the time to reply MaJP. I think part of the the problem may have been declaring Diff as Byte because it can take negative values. Before implementing your suggestion I'll continue to test the results because at the moment they're sensible. Useful tip anyway, thanks again.

#### Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!