vbams-accesstype-mismatch

What is wrong with the variable?


ID assigned_to work_order_id close_wo_date close_date work_order_status post_code order_type
611802 John, Ed,Al, Dexter TMN-09/10/24-2113-0133 2024-10-10 15:24:00.000 2024-10-10 15:23:00.000 Closed 2113 TMN

Datatypes: AutoNumber, Short Text, Short Text, ...

I want to separate the values in the 'assigned_to' column. However, I get a type mismatch error on line 16.

workOrderId = rstIn!work_order_id

I can't figure out what the problem is.

Option Compare Database

Sub TransformTable()
    Dim dbs As DAO.Database
    Dim rstIn As DAO.Recordset
    Dim rstOut As DAO.Recordset
    Dim arrParms() As String
    Dim workOrderId() As String
    Dim i As Long
    Set dbs = CurrentDb
    Set rstIn = dbs.OpenRecordset("teszt_in", dbOpenForwardOnly)
    Set rstOut = dbs.OpenRecordset("teszt_out", dbOpenDynaset)
    Do While Not rstIn.EOF
        If Not IsNull(rstIn!assigned_to) Then
            arrParms = Split(rstIn!assigned_to, ",")
            workOrderId = rstIn!work_order_id
            For i = 0 To UBound(arrParms)
                rstOut.AddNew
                rstOut!ID = rstIn!ID
                rstOut!assigned_to = arrParms(i)
                rstOut!work_order_id = workOrderId(i)
                rstOut.Update
            Next i
        End If
        rstIn.MoveNext
    Loop
    rstIn.Close
    rstOut.Close
End Sub

Solution

  • workOrderId should not be an array, so use:

    
    Dim workOrderId As String
    
    ' <snip>
    
    rstOut!work_order_id = workOrderId
    
    ' or:
    
    rstOut!work_order_id.Value = workOrderId