Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    iMaCannot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    9

    Access 2010 Type mismatch

    This is my first post on this forum as I have a peculiar type mismatch problem. I have two PC's running the same Access program and on one it's fine but the other exhibits this Type Mismatch error 13.

    The VBA is in Form (frmClientCALLReminder) and is as follows:

    '==================== START of Form code =================================

    Private Sub AddAppt_Click()


    ' Comments:
    ' Params :
    ' Modified:

    On Error GoTo Err_AddAppt_Click

    ' Save record
    DoCmd.RunCommand acCmdSaveRecord

    Dim outobj As Outlook.Application
    Dim outappt As Outlook.AppointmentItem
    Set outobj = CreateObject("outlook.application")
    Set outappt = outobj.CreateItem(olAppointmentItem)

    With outappt

    ' This next line causes the type mismatch.
    .Start = Me!ApptDate & " " & Me!cmbApptTime

    .Duration = Me!ApptLength
    .Subject = Me!Appt
    If Not IsNull(Me!ApptNotes) Then
    .Body = Me!ApptNotes
    End If
    If Not IsNull(Me!ApptLocation) Then
    .LOCATION = Me!ApptLocation
    End If
    If Me!ApptReminder Then
    .ReminderMinutesBeforeStart = Me!ReminderMinutes
    .ReminderSet = True
    End If
    .Save
    End With

    blnCreateReminder = True

    ' Release the Outlook object variable.
    Set outobj = Nothing
    ' Set the AddedToOutlook flag, save the record, display a message.
    Me!AddedToOutlook = True
    DoCmd.RunCommand acCmdSaveRecord

    'Disabled message for now
    MsgBox "Reminder added to Outlook"

    Me.Appt = ""
    Me.ApptDate = 0
    'Me.ApptTime = 0
    Me.ApptNotes = ""

    DoCmd.Close

    Exit Sub

    Exit_AddAppt_Click:
    Exit Sub

    Err_AddAppt_Click:
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description
    Resume Exit_AddAppt_Click

    End Sub

    '==================== END of Form code =================================


    VBA References as follows:

    Click image for larger version. 

Name:	AccessReferences.png 
Views:	16 
Size:	11.7 KB 
ID:	18242


    I would appreciate any suggestions as to what it might be. Right now it seems to be machine specific.

    Thanks in advance.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    change the code to :

    Code:
    Err_AddAppt_Click:
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description
    Resume Exit_AddAppt_Click
    RESUME
    When the error msgbox opens, hit ctrl-break
    debug
    put the cursor on this new RESUME line
    right-click, SET NEXT STATEMENT
    press F8 (to step thru code)
    the run-line will move to the bad piece of code...and you can tell us (or yourself) where the error occurs.

  3. #3
    iMaCannot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    9
    Thanks for taking the time to reply and the debug resume tip.

    This is the failing line in yellow below..

    The two fields are linked to a table which has them as type Date/Time.
    However the form Text format for ApptDate is Plain text and selected from the date picker. The cmbApptTime is selecting the Time from a table called tblWorkTimes which also has a Date/Time format.


    Click image for larger version. 

Name:	DebugResume.png 
Views:	13 
Size:	4.6 KB 
ID:	18243

    One of the two machines that run this works fine. Both machines are 32bit Access and OS.

    It's a bit of a mystery.

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Since the error is occuring with an Outlook object, it suggests it might originate with Outlook, not Access.

    Are both PC's running the same version of Outlook, and is it configured the same way on both?

    John

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    One other thing to try is to comment out the offending line and run the routine again.

    It could be (and I have seen this sort of thing) that the error is something else entirely, and that it will fail again, this time on the .Duration= me!ApptLength line.

    John

  6. #6
    iMaCannot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    9
    John
    I did as you suggested and commented out the failing line. It now works and adds appointment to Outlook with todays date a time.

    So there is progress. but what else can I try wth these data fields.

    Thank you.

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    With a little help from MS Access "Help":

    your line to set the start date/time should look like this:

    .Start = #9/29/2014 1:30:00 PM#

    in other words, it is expecting a date, not a character string.

    Try this:

    .Start = cdate(Me!ApptDate & " " & Me!cmbApptTime)

    I tested this and it worked perfectly:

    strTest = "9/29/2014 1:30:00 PM"
    .Start = CDate(strTest)

    John

  8. #8
    iMaCannot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    9
    John
    Thanks for that.
    The

    strTest = "9/29/2014 1:30:00 PM"
    .Start = CDate(strTest)

    works fine.
    But the .Start = cdate(Me!ApptDate & " " & Me!cmbApptTime) doesn't.

    At least I know it's all down to these two fields not having the correct format.
    I'm going to try the date field on its own. And see what happens.

    I'll let you know what the result is.

  9. #9
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by iMaCannot View Post

    Dim outappt As Outlook.AppointmentItem

    With outappt
    Help says that With can be used against Objects or User Defined Datatypes; I'm not sure that you can use it against a Variable, as you're doing here. When I try doing it, I get the same error.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  10. #10
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi Missinglinq -

    As far as I know, using a variable in a with construct works fine - I do it all the time:

    Dim rst as Recordset
    set rst=db.openrecordset(....)
    with rst
    end with

    and I have never encountered any problems.

    John

  11. #11
    iMaCannot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    9
    John

    Thanks for all your assistance.

    I tried using the original ApptDate on its own and it worked.

    Then I tried the original ApptTime on its own and it worked.

    There appears to be a problem with the concatenation. Even using CDate doesn't cure the problem on this PC.

    I have now tried stripping the with out and replacing it with fully qualified names. outappt.start etc. Still no go.

    The code I'm using was originally from an Access expert's code book. We also have to remember that it does work on the other PC.

    I will take a rest now and do a lot more reading.

    Thanks again
    Last edited by iMaCannot; 09-30-2014 at 01:57 AM. Reason: Not sure of facts

  12. #12
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    iMaCannot -

    I you can show us what the expression Me!ApptDate & " " & Me!cmbApptTime actually looks like it would help. I agree, one of them (date or time) probably isn't formatted correctly.

    When you say the CDate with your expression doesn't work, what are you getting - thae same error?

    John

  13. #13
    iMaCannot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    9
    To everyone that helped.

    Thanks a lot.

  14. #14
    iMaCannot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    9
    Quote Originally Posted by John_G View Post
    iMaCannot -

    I you can show us what the expression Me!ApptDate & " " & Me!cmbApptTime actually looks like it would help. I agree, one of them (date or time) probably isn't formatted correctly.

    When you say the CDate with your expression doesn't work, what are you getting - thae same error?

    John
    John

    That is exactly right. I'm getting the same error. If I take each of the variables and use them separately then there is no problem.

    iMaCannot

  15. #15
    iMaCannot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    9
    My code at the top of this thread shows the line at fault.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-18-2014, 12:26 PM
  2. Replies: 9
    Last Post: 11-20-2013, 03:16 PM
  3. Replies: 1
    Last Post: 06-28-2013, 12:54 PM
  4. Replies: 2
    Last Post: 08-06-2012, 08:27 AM
  5. Type mismatch Error after upgrading to Access 2010
    By twm07073 in forum Programming
    Replies: 7
    Last Post: 06-13-2012, 10:07 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