Results 1 to 3 of 3
  1. #1
    Jaron is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    63

    Run-time error 13 type Mismatch

    Hello. I have been testing some code I found online that is supposed to take entire column of data in a table or query and convert it to a single string.
    With a command button, I set the value of a textbox to contain the result of the function.

    Here is what I have:

    Code:
    Private Sub Command117_Click()
    Me![Work Desc] = CombineList("WeeklyTimesheetQueryResults", "Description", ";")
    End Sub
    ...and the function:
    Code:
     Option Compare Database
    Function CombineList(strSource As String, strField As String, strDelim As String, Optional strTextQual As Variant) As String
    '   Combines a single column from multiple records into a single string
    '   Arguments
    '       strSource = name of query or table
    '       strField = name of field you want to combine
    '       strDelim = delimiter to use to separate each value
    '       strTextQual = text qualifer to use around each field (optional)
     
        Dim myDB As DAO.Database
        Dim myRS As DAO.Recordset
        Dim myRecCount As Long
        Dim myTempString As String
        
        Set myDB = CurrentDb
        Set myRS = myDB.OpenRecordset(strSource, dbOpenDynaset)
        
        myRecCount = DCount(strField, strSource)
        If myRecCount > 0 Then
            With myRS
                .MoveFirst
                Do While Not .EOF
                    myTempString = myTempString & strTextQual & myRS(strField) & strTextQual & strDelim
                    .MoveNext
                Loop
            End With
        End If
        Set myRS = Nothing
        Set myDB = Nothing
        If Len(myTempString) > 0 Then CombineList = Left(myTempString, Len(myTempString) - 1)
        
    End Function
    The type mismatch error comes up with the following line:
    Code:
    myTempString = myTempString & strTextQual & myRS(strField) & strTextQual & strDelim
    what might I be doing wrong here?



    Thank you in advance for any suggestions.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Is the data actually number or date/time type? Those don't use the string qualifier. Date/times use # and numbers nothing.

    Here is another version of this procedure http://allenbrowne.com/func-concat.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Jaron is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    63
    Ok, nice. Yes that one worked good. thanks.

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

Similar Threads

  1. Run-time error 13: type mismatch
    By ehe in forum Programming
    Replies: 3
    Last Post: 01-13-2013, 12:58 AM
  2. run-time error '13' type mismatch
    By teebumble in forum Forms
    Replies: 8
    Last Post: 12-03-2012, 01:18 PM
  3. Error: Run-time error '13' Type mismatch
    By uronmapu in forum Access
    Replies: 1
    Last Post: 09-07-2012, 05:38 AM
  4. run-time error 13 , type mismatch
    By Compufreak in forum Programming
    Replies: 8
    Last Post: 08-13-2012, 12:17 AM
  5. Run-time error '13': Type mismatch
    By uronmapu in forum Access
    Replies: 2
    Last Post: 07-10-2012, 07:59 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