Results 1 to 3 of 3
  1. #1
    Baalu is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    7

    Type Mismatch Error While Executing The Below Functions, Access 2010

    Hi Friends,

    I am trying to calculate the difference between quarters, I wrote the below two functions, while executing I am getting Type Mismatch error. Please help me.

    Code:
    Public Function Calc_Quarter(ByVal dtDate As Date) As String
    On Error GoTo Err_CQ
    
    Dim CD As String
    Dim dt As Date
    Dim Qyear, Qmonth, Quarter As Integer
    
    dt = dtDate
    Qyear = Year(dt)
    Qmonth = Month(dt)
    
    If Qmonth = 1 Then
        Qyear = Qyear - 1
        Qmonth = 12
    Else
        Qmonth = Qmonth - 1
    End If
    
    Select Case Qmonth
        Case 1, 2, 3
            Quarter = 1
        Case 4, 5, 6
            Quarter = 2
        Case 7, 8, 9
            Quarter = 3
        Case 10, 11, 12
            Quarter = 4
    End Select
    
    Calc_Quarter = "Q" & Quarter & " " & Qyear
    
    Err_CQ:
    If Err.Number <> 0 Then
    'MsgBox "Error while calculating Quarter"
    Calc_Quarter = "Error"
    End If
    End Function
    
    
    
    
    
    Public Function EvidenceValid(ByVal dtDate As Date) As Boolean
    On Error GoTo Err_EvidenceValid
    
    Dim CurDt, GivenDt As Date
    Dim CurDtQ, CurDtY, GvDtQ, GvDtY, QtDiff As Integer
    
    CurDt = Date
    GivenDt = dtDate
    
    CurDtQ = CInt(Left(Calc_Quarter(CurDt), 1))
    CurDtY = CInt(Mid(Calc_Quarter(CurDt), 2))
    GvDtQ = CInt(Left(Calc_Quarter(GivenDt), 1))
    GvDtY = CInt(Mid(Calc_Quarter(GivenDt), 2))
    QtDiff = ((CurDtY * 4) + CurDtQ) - ((GvDtY * 4) + GvDtQ)
    
    If QtDiff > 1 Then
    EvidenceValid = False
    Else
    EvidenceValid = True
    End If
    
    Err_EvidenceValid:
    If Err.Number <> 0 Then
    EvidenceValid = False
    Exit Function
    End If
    End Function
    


    I am calling these two functions from a query and I am getting error while executing the "EvidenceValid" Function.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    A couple of thoughts:

    This doesn't work as you think
    Code:
    Dim Qyear, Qmonth, Quarter As Integer
    In Access you must explicitly dim variables.

    Dim Qyear as Integer
    Dim QMonth as Integer
    Dim Quarter as Integer

    or
    Dim Qyear as Integer, QMonth as Integer...

    Your approach results in qYear, qMonth as type Variant. Only quarter will be Integer.

    You might want to research the DateDiff function.

  3. #3
    Baalu is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    7
    Hi,

    Finally I found the actual problem and resolved it.
    Problem is with Cint() which I used, I should actually use Val here.
    Now the issue is resolved.

    Thanks for your support,
    Baalu

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

Similar Threads

  1. Access 2010 Type mismatch
    By iMaCannot in forum Programming
    Replies: 15
    Last Post: 09-30-2014, 01:54 AM
  2. Replies: 5
    Last Post: 09-18-2014, 12:26 PM
  3. Replies: 9
    Last Post: 11-20-2013, 03:16 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

Tags for this Thread

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