Calculation on form not working

warmduvet

Registered User.
Local time
Tomorrow, 02:04
Joined
Oct 10, 2004
Messages
10
Hi, I have a form where I enter student data and lesson details such as lesson type number of lesson and total cost the following code is supposed to do the calculation to provide the total cost and display it in the txttotal text box.

It doesn't :(

Code:
 Private Sub txtlessonnum_Exit(Cancel As Integer)
Dim numlessons As Integer
    Dim total As Integer
    
        
    If (Me.cmblesson.Text = "lesson1") Then
        total = ((50 / 3) * numlessons)
        ElseIf (Me.cmblesson.Text = "lesson2") Then
            total = (((50 / 3) * 2) * numlessons)
                ElseIf (Me.cmblesson.Text = "lesson3") Then
                   total = (50 * numlessons)
    End If
    MsgBox (numlessons)
    
    Me.txttotal.Value = total
    'Me.Refresh

End Sub

I get this error message: runtime error 2185
"you can't reference a property or method for a control unless the control has the focus"

TIA

WD
 
For starters, I don't see where you set 'numlessons'.


kh
 
Thanks for the replies, have sorted it out

Code:
Private Sub txtlessonnum_AfterUpdate()
Dim numlessons As Variant
Dim total As Integer

    numlessons = Me.txtlessonnum & ""
   
    If (Me.cmblesson = 1) Then
        total = ((50 / 3) * numlessons)
    ElseIf (Me.cmblesson = 2) Then
        total = (((50 / 3) * 2) * numlessons)
    ElseIf (Me.cmblesson = 3) Then
        total = (50 * numlessons)
    End If
   
    Me.txttotal.Value = total
          
End Sub

WD
 

Users who are viewing this thread

Back
Top Bottom