Results 1 to 7 of 7
  1. #1
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156

    Run time error 13 "type mismatch"


    Me again. I found the below file and it works great,however when you click on one of the date boxes with out choosing a departmentand employee you get the run time error. I would like to eliminate the run timeerror and have it replaced with a message box that says you must choose adepartment and employee.

    This is the code that is giving the error

    Code:
    Function SendToInputBox(mynum)
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim f As Form
        Dim g As String
        Dim MyDate As Date
        Dim UName As String
        
        Set db = CurrentDb()
        Set rs = db.OpenRecordset("tblInput",dbOpenDynaset)
        Set f = Forms!frmCalendar
    Code:
    MyDate = Format(f("Date" & mynum),"mm/dd/yyyy")
        UName = f.cboUser.Column(1)
        g = Format(MyDate, "dddd mmmm d, yyyy")
        
        rs.FindFirst "InputDate = #" & MyDate &"# AND UserID = " & glngUserID
        
        DoCmd.OpenForm "frmInputBox"
        With Forms!frmInputBox
        
        If Not rs.NoMatch Then
               !txtAttendanceReason = rs!AttendanceReason
                !InputText =rs!InputText
                
        End If
            !InputDay = mynum
            !InputDate = MyDate
            !InputFor = g
            !NameLabel1.Caption = UName:
            !original_text =f.Controls("Text" & mynum)
            !InputText =f.Controls("Text" & mynum)
            !InputText.SetFocus
            End With
        
        SendKeys "{F2}^{HOME}", False
    End Function


    It is the line in red that is highlighted yellow when I get the error The belowis the file it self. I also must say it is very well done. Just has the aboveclitch.

    Attached Files Attached Files

  2. #2
    nrgins's Avatar
    nrgins is offline some guy
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    62
    Without knowing more about what this code is or what it does or where department and employee are or what they are, I can only answer in general.

    To prevent the error if Department and Employee aren't completed, you can simply put at the top your routine:

    Code:
    If IsNull(f.Department) Or IsNull(f.Employee) Then Exit Function
    Change "Department" and "Employee" to whatever the names of the controls actually are.

  3. #3
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    The code open a form named "input Box". This form allows the user to choose from a list why the employee has that day off and input a comment. It only works if the user chooses an department and employee first. If not that error pops up. The user does not no why the error has popped up, that is why I would like to change it to a message box saying you must choose an department and employee. Another option would be have a default department and employee automatically inserted when the calendar is opened so the error does not occur.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Code:
        Set db = CurrentDb()
        Set rs = db.OpenRecordset("tblInput", dbOpenDynaset)
        Set f = Forms!frmCalendar
        
        If Len(f.cboDepartment.Column(1) & vbNullString) = 0 Then
            MsgBox "You must select a department and employee"
            Exit Function
        End If
        If Len(f.cboUser.Column(1) & vbNullString) = 0 Then
            MsgBox "You must select a department and employee"
            Exit Function
        Else
            UName = f.cboUser.Column(1)
        End If
        MyDate = Format(f("Date" & mynum), "mm/dd/yyyy")
        g = Format(MyDate, "dddd mmmm d, yyyy")
    Add the above code changes to function SendToInputBox.

  5. #5
    CHEECO is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2016
    Posts
    156
    That worked perfect. Thank-you very much.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Glad to help. Good luck with that project!

  7. #7
    nrgins's Avatar
    nrgins is offline some guy
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    62
    The code open a form named "input Box".
    OK, then put what I wrote in the line before the code opens a form called "input box." If you want to include a message, then change it to this:
    Code:
    If IsNull(f.Department) Or IsNull(f.Employee) Then 
        MsgBox "You must first enter a department and an employee.", vbinformation
        Exit Function
    End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Type mismatch on a "Split" statement
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 12-07-2014, 06:55 AM
  2. Replies: 1
    Last Post: 08-05-2011, 12:05 PM
  3. Replies: 2
    Last Post: 05-17-2011, 02:40 PM
  4. aSTR = Dir("C:\*.*") >> "Type Mismatch"
    By JGrant in forum Programming
    Replies: 1
    Last Post: 03-28-2009, 05:17 AM
  5. "Type Mismatch" Error
    By elmousa68 in forum Access
    Replies: 2
    Last Post: 12-05-2006, 08:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums