Results 1 to 3 of 3
  1. #1
    RayMilhon is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071

    Criteria Error that makes no sense


    I have a report in MS Access 2010. In the Group Footer Part of the calculations are from a different record source than the Main Report. I've built VBA Code that runs a query and returns the records that populate the 4 fields on the report. It's worked fine until now. Now everytime I run the report I get a Datatype Mismatch in criteria expression. The confusing part is it doesn't occur until the 4th page of the report even though the only thing that changes is the Criteria which consists of 2 fields firstname and lastname. Copying the sql into query analyzer gives me the same error. However, if I pull out the criteria and run the report the data provided matches what I have If I do a copy and paste of either into the criteria of the query I get the same error. Here's the query

    Code:
    SELECT HVVMG.Providers, [Doctor-Patient Communication] as DP_comm,[Office Staff] as off,[Continuity and Coordination of Care] as coord_of_care,HVVMG.[Overall Ratings - Provider] as Overall, HVVMG.[Timely Access to Care] As Access, HVVMG.Respondents,HVVMG.Facilities as fac, HVVMG.all_ques_avg,HVVMG.all_ques_avg_rank,HVVMG.MTC_75,HVVMG.MTC_90 FROM HVVMG Where fnLastname([Providers]) = "ALTAYS" AND FnfirstName([Providers]) = "MIKE";
    
    
    'Functions
    
    Public Function fnlastname(ByVal strname As String) As String
        Dim tmpstr As String
        tmpstr = Left(strname, InStr(1, strname, ",") - 1)
        If Right(tmpstr, 4) = "M.D." Then
            tmpstr = Left(tmpstr, Len(tmpstr) - 4)
        End If
        fnlastname = tmpstr
        
    End Function
    
    Public Function fnfirstname(ByVal strname As String) As String
        Dim tmpstr As String, lngfirstcomma As Long, lngsecondcomma As Long
    
        tmpstr = Right(strname, Len(strname) - InStr(1, strname, ","))
        
        Select Case Left(tmpstr, 4)
            Case Is = " DO ", Is = " MD "
                tmpstr = Right(tmpstr, Len(tmpstr) - 4)
            Case Is = " M.D", Is = " MD,", Is = " DO,", Is = " D.O", Is = "MD (", Is = "(PCP"
                lngfirstcomma = InStr(1, tmpstr, ",")
                lngsecondcomma = InStr(lngfirstcomma, tmpstr, ",")
                tmpstr = Right(tmpstr, Len(tmpstr) - lngsecondcomma)
        End Select
    
        tmpstr = Trim(tmpstr)
        If Left(tmpstr, 5) = "(PCP)" Then
            tmpstr = Right(tmpstr, Len(tmpstr) - 6)
        End If
        If InStr(1, tmpstr, " ") > 0 Then
            fnfirstname = Left(tmpstr, InStr(1, tmpstr, " ") - 1)
        Else
            fnfirstname = tmpstr
        End If
        
    End Function

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    First, I would check your data

    this line of your code relies on there being a comma in strName

    tmpstr = Left(strname, InStr(1, strname, ",") - 1)

    if there isn't Instr will return 0 which means the Left function will return an error

  3. #3
    RayMilhon is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Ajax, the strname is always in the format "Lastname, Degree, firstname MI" All of them are Primary Care Physicians and will all have the name in that format.

    However, with that said I did go back and look at the Data and discovered there were 3 blank records appended to the table. The data for this section of the report comes to me via Excel spreadsheet which I then import into MS Access. This is the first time there were extra records. I'll have to relook at the spreadsheet and determine what happened there. Deleted the 3 extra records and it works great. Thanks

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

Similar Threads

  1. What makes a subform stop working?
    By snowboarder234 in forum Forms
    Replies: 5
    Last Post: 06-01-2016, 03:00 PM
  2. Does this table relationship make sense?
    By MatthewGrace in forum Database Design
    Replies: 9
    Last Post: 10-05-2014, 03:59 PM
  3. A form that makes multiple entries
    By dimits in forum Forms
    Replies: 3
    Last Post: 06-09-2014, 12:53 PM
  4. How can I add username when user makes an update?
    By alexandervj in forum Access
    Replies: 14
    Last Post: 02-20-2014, 08:53 PM
  5. From that makes Multiple records
    By sgp667 in forum Forms
    Replies: 8
    Last Post: 10-12-2012, 06:51 PM

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