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

Type Mismatch

Status
Not open for further replies.

ppedersen1

Technical User
Oct 14, 2002
43
US
Hello, I created a simple form in MSAccess and for some reason I am getting a "Type Mismatch" error. The highlighted error is the "+" below where it says "Wins = Wins + 1." This doesn't seem right. Can someone help me out here?

Here is my VBA code:

Private Sub cmdSpin_Click()
Image15.Visible = False 'hide coins
Label1.Caption = Int(Rnd * 10) 'pick numbers
Label2.Caption = Int(Rnd * 10)
Label3.Caption = Int(Rnd * 10)
Spins = Spins + 1
'if any caption is 7 display coin stack and beep
If (Label1.Caption = 7) Or (Label2.Caption = 7) _
Or (Label3.Caption = 7) hen
Image15.Visible = True
Beep
Wins = Wins + 1
Label16.Caption = "Wins: " & Wins
End If
lblRate.Caption = Rate(Wins, Spins)
End Sub

I also created two modules. The Wins module simply says
"Public Wins"
 
Hi,

"(Label3.Caption = 7) hen"
if you cut 'n pasted this then 'hen' should be 'then'.

If that isn't the problem then after:

Private Sub cmdSpin_Click()

type this:

dim Wins as integer.

If that doesn't work rename Wins to Mywins (all references, 'Wins' maybe reserved) and get rid of 'dim Wins as integer'.

Regards,

Darrylle



"Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
Seems to me your type mismatch may be occurring on the line above - the captions are string objects, and you're comparing them to numbers. If that's not it, then when you get the error, find out in the immediate window what the value and type of wins is
?wins
?typename(wins)
Maybe you had wins declared as a non-numeric variable at module-level?
Rob
[flowerface]
 
Hi Rob,

Well spotted.

You're right, although he's not COMPARING the label.caption to numbers, he's ASSIGNING numbers to the label.caption.

If so, should be:

Label1.Caption = STR(Int(Rnd * 10)) etc.

Although, I'd assume that it should convert automatically.

Regards

Darrylle "Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top