Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of empty columns in TDF input #562

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions Version Control.accda.src/modules/clsDbTableData.cls
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Private Sub ImportTableDataTDF(strFile As String)
Dim varLine As Variant
Dim varHeader As Variant
Dim intCol As Integer
Dim strColName As String
Dim strValue As String

Perf.OperationStart "Import TDF Data"
Expand Down Expand Up @@ -229,30 +230,38 @@ Private Sub ImportTableDataTDF(strFile As String)
rst.AddNew
' Loop through fields
For intCol = 0 To UBound(varHeader)
strColName = varHeader(intCol)
' Check to see if field exists in the table
If dCols.Exists(varHeader(intCol)) Then
' Check for empty string or null.
If dCols.Exists(strColName) Then
' Check for empty string in input.
If varLine(intCol) = vbNullString Then
' The field could have a default value, but the imported
' data may still be a null value.
If Not IsNull(rst.Fields(varHeader(intCol)).Value) Then
' Could possibly hit a problem with the storage of
' zero length strings instead of nulls. Since we can't
' really differentiate between these in a TDF file,
' we will go with NULL for now.
'rst.Fields(varHeader(intCol)).AllowZeroLength
rst.Fields(varHeader(intCol)).Value = Null
' The file format does not distinguish
' between null (no value) and empty string
fld = rst.Fields(strColName)
If fld.Type = dbText Or fld.Type = dbMemo Then
If Not fld.AllowZeroLength Then
' Error: field is required but no value provided
Else
If fld.Required Then
' We know in this particular case,
' null is not permitted, therefore
' empty string must be intended
rst.Fields(strColName).Value = ""
End If
End If
End If
' Otherwise, assume null was intended:
' leave result .Value unset
Else
' Perform any needed replacements
strValue = FormatStringFromTDF(CStr(varLine(intCol)))
If strValue <> CStr(varLine(intCol)) Then
' Use replaced string value
rst.Fields(varHeader(intCol)).Value = strValue
rst.Fields(strColName).Value = strValue
Else
If strValue <> UNSUPPORTED_DATA_TYPE Then
' Use variant value without the string conversion
rst.Fields(varHeader(intCol)).Value = varLine(intCol)
rst.Fields(strColName).Value = varLine(intCol)
End If
End If
End If
Expand Down