starclassic
Technical User
Hello everyone,
I have this SQL Statement:
'Add record to first table contact to print the First Contact Letter
DoCmd.RunSQL "INSERT INTO tblFirstContact (LName,Address,Address1,Address2,Address3,City,Province,PostalCode," _
& "Year,Make,Model,Vin,AFOCode,AgentCode,AgentName,PolicyNumber,Message,SystemCalculateAmountOwing)" _
& "Values ('" & FX(rst![LName]) & "', '" & FX(rst![Address]) & "', '" & rst![Address1] & "', '" & rst![Address2] & "'," _
& "'" & rst![Address3] & "', '" & rst![City] & "','" & rst![Province] & "', '" & rst![PostalCode] & "', " _
& "'" & rst![Year] & "','" & rst![Make] & "', '" & rst![Model] & "', '" & rst![Vin] & "','" & rst![AFOCode] & "'," _
& "'" & rst![AgentCode] & "','" & FX(rst![AgentName]) & "','" & rst![PolicyNumber] & "','" & LetterMessage & "'," _
& "'" & rst![SystemCalculateAmountOwing] & "')"
'Function to deal with (') apostrophe in the string
Public Function FX(strInput As String, Optional strQuoteChar As String = "'") As String
On Error GoTo ErrorHandler
Dim lsWork As String
FX = strInput
lsWork = strInput
If Len(lsWork) > 0 Then
Do While InStr(lsWork, strQuoteChar) > 0
lsWork = Replace(lsWork, strQuoteChar, Chr$(&HFF))
Loop
Do While InStr(lsWork, Chr$(&HFF)) > 0
lsWork = Replace(lsWork, Chr$(&HFF), strQuoteChar & strQuoteChar)
Loop
End If
FX = lsWork
FX_Done:
On Error Resume Next
Exit Function
ErrorHandler:
Dim lngErrNum As Long: Dim strErrDesc As String: lngErrNum = Err.Number:
strErrDesc = Err.Description
MsgBox "Err#" & Err.Number & vbCrLf & vbCrLf & "Desc: " & 30# & Err.Description, vbExclamation, "FixQuotes"
Resume FX_Done
Resume ' for debug
End Function
FX is a function to deal with (') Apostrophe and now my problems is that some of the Fieldname like [Address] values are Null. Gives a error invalid value "Null"
Any ideas of function to deal with null values.
I have this SQL Statement:
'Add record to first table contact to print the First Contact Letter
DoCmd.RunSQL "INSERT INTO tblFirstContact (LName,Address,Address1,Address2,Address3,City,Province,PostalCode," _
& "Year,Make,Model,Vin,AFOCode,AgentCode,AgentName,PolicyNumber,Message,SystemCalculateAmountOwing)" _
& "Values ('" & FX(rst![LName]) & "', '" & FX(rst![Address]) & "', '" & rst![Address1] & "', '" & rst![Address2] & "'," _
& "'" & rst![Address3] & "', '" & rst![City] & "','" & rst![Province] & "', '" & rst![PostalCode] & "', " _
& "'" & rst![Year] & "','" & rst![Make] & "', '" & rst![Model] & "', '" & rst![Vin] & "','" & rst![AFOCode] & "'," _
& "'" & rst![AgentCode] & "','" & FX(rst![AgentName]) & "','" & rst![PolicyNumber] & "','" & LetterMessage & "'," _
& "'" & rst![SystemCalculateAmountOwing] & "')"
'Function to deal with (') apostrophe in the string
Public Function FX(strInput As String, Optional strQuoteChar As String = "'") As String
On Error GoTo ErrorHandler
Dim lsWork As String
FX = strInput
lsWork = strInput
If Len(lsWork) > 0 Then
Do While InStr(lsWork, strQuoteChar) > 0
lsWork = Replace(lsWork, strQuoteChar, Chr$(&HFF))
Loop
Do While InStr(lsWork, Chr$(&HFF)) > 0
lsWork = Replace(lsWork, Chr$(&HFF), strQuoteChar & strQuoteChar)
Loop
End If
FX = lsWork
FX_Done:
On Error Resume Next
Exit Function
ErrorHandler:
Dim lngErrNum As Long: Dim strErrDesc As String: lngErrNum = Err.Number:
strErrDesc = Err.Description
MsgBox "Err#" & Err.Number & vbCrLf & vbCrLf & "Desc: " & 30# & Err.Description, vbExclamation, "FixQuotes"
Resume FX_Done
Resume ' for debug
End Function
FX is a function to deal with (') Apostrophe and now my problems is that some of the Fieldname like [Address] values are Null. Gives a error invalid value "Null"
Any ideas of function to deal with null values.