Results 1 to 6 of 6

Codes to Surpass "Type Mismatch"

Threaded View

  1. #1
    Registered User
    Join Date
    04-13-2009
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    94

    Codes to Surpass "Type Mismatch"

    Hi. i made a form named calculator with "calculate" button for value execution from textboxes.
    the textboxes have default corresponding default values in it. the first to do is press "clear" button first so that the default values disappear.

    Everytime i open the form and press the "calculate" button as first action an error comes up showing "type mismatch". what code to insert so that if "calculate" be the first to be pressed a message box will appear which says "please press clear button first".

    Please see attached access sample form.
    here is the code inside.

    thanks.

    Option Compare Database
    Option Explicit
    Private Sub Calc_button_Click()
        Dim Label1 As Long, Label2 As Long, Label3 As Long, Label4 As Long, Label5 As Long, Label6 As Double
        Label1 = IIf(Me.cat1a.Value = "", 0, Me.cat1a.Value) * IIf(Me.cat1b.Value = "", 1, Me.cat1b.Value)
        Label2 = IIf(Me.cat2b.Value = "", 0, Me.cat2b.Value) * IIf(Me.cat2a.Value = "", 1, Me.cat2a.Value)
        Label3 = IIf(Me.cat3b.Value = "", 0, Me.cat3b.Value) * IIf(Me.cat3a.Value = "", 1, Me.cat3a.Value)
        Label4 = IIf(Me.cat4b.Value = "", 0, Me.cat4b.Value) * IIf(Me.cat4a.Value = "", 1, Me.cat4a.Value)
        Label5 = IIf(Me.cat5b.Value = "", 0, Me.cat5b.Value) * IIf(Me.cat5a.Value = "", 1, Me.cat5a.Value)
        If Me.Prod.Value <> "" Then
          Label6 = Me.Prod.Value
        Else
         MsgBox "Productivity / Unit Hour ??"
            Exit Sub
        End If
        Me.Equal.Value = (Label1 + Label2 + Label3 + Label4 + Label5) / Label6
    End Sub
    Private Sub Clear_button_Click()
        Me.cat1a.Value = ""
        Me.cat2a.Value = ""
        Me.cat3a.Value = ""
        Me.cat4a.Value = ""
        Me.cat5a.Value = ""
        Me.cat1b.Value = ""
        Me.cat2b.Value = ""
        Me.cat3b.Value = ""
        Me.cat4b.Value = ""
        Me.cat5b.Value = ""
        Me.Prod.Value = ""
        Me.Equal.Value = ""
        
    End Sub
    
    Sub Command16_Click()
        DoCmd.Close
    End Sub
    Attached Files Attached Files
    Last edited by macky1730; 10-11-2010 at 08:59 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1