joyfullservice / msaccess-vcs-addin

Synchronize your Access Forms, Macros, Modules, Queries, Reports, and more with a version control system.
Other
203 stars 40 forks source link

Build from source: export of tab-delimited table data fails at empty values #64

Closed effjot closed 3 years ago

effjot commented 4 years ago

I need to save some numeric table data. I exported it in tab-delimited format, which is easier to look at ;-)

When building from source, I get “Runtime error 3421: Data type conversion error”.

Debugger puts me in clsDbTableData, line 165:

' Read file line by line
Set stm = FSO.OpenTextFile(strFile, ForReading, False)
Set rst = dbs.OpenRecordset(strTable)
Do While Not stm.AtEndOfStream
    strLine = stm.ReadLine
    If Not IsArray(varHeader) Then
        ' Read header line
        varHeader = Split(strLine, vbTab)
    Else
        ' Data line
        varLine = Split(strLine, vbTab)
        rst.AddNew
            ' Loop through fields
            For intCol = 0 To UBound(varHeader)
                ' Check to see if field exists in the table
                If dCols.Exists(varHeader(intCol)) Then
                    ' Perform any needed replacements
                    strValue = MultiReplace(CStr(varLine(intCol)), _
                        "\\", "\", "\r\n", vbCrLf, "\r", vbCr, "\n", vbLf, "\t", vbTab)
                    If strValue <> CStr(varLine(intCol)) Then
                        ' Use replaced string value
                        rst.Fields(varHeader(intCol)).Value = strValue
                    Else
                        ' Use variant value without the string conversion
                        rst.Fields(varHeader(intCol)).Value = varLine(intCol)  ' <-- debugger drops me here
                    End If
                End If
            Next intCol
        rst.Update
    End If
    ' Increment log, just in case this takes a while.
    Log.Increment
Loop

In my example, strLine is 1 4 2 4 4 6 6 (with 2 tabs at the end), intCol is 7, varLine(intCol) = "". When I hover over the .Value of rst.Fields(varHeader(intCol)).Value, it’s Null

Importing Nulls from XML works, however.

effjot commented 4 years ago

I added a check for null values to the code. I’d like to test it some more, but you can have a look at https://github.com/effjot/msaccess-vcs-integration/commits/joyfullservice_fj

However, tab-delimited files are written using the locale, so files probably are not portable between locales (esp. regarding decimal point vs. comma)

joyfullservice commented 3 years ago

I have implemented a fix for this... Could you test it out in your database and make sure it is working as expected? Feel free to reopen this issue if anything needs to be adjusted.

effjot commented 3 years ago

Sorry, I forgot to reply. Empty values now work with both Tab and XML files. Thanks!