We help IT Professionals succeed at work.

Hiding a null Control in Json string

Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc used Ask the Experts™
on
On the tax labels in the Json code (Ms Access VBA) below, I want to hide the control field in Tax Class B if it does not contain a value in the final Json string or code. Currently it is showing a “Null” but unfortunately the machine cannot accept that, it should NEVER show at all cost.
If an event where all the two tax labels are having values then the actual labels attached to the controls must show the actual value, if not then no show.

Please check line 26 in the code below

{
"PosSerialNumber": "16777773",
"IssueTime": "20190101201045",
"TransactionType": 0,
"PaymentMode": 0,
"SaleType": 0,
"LocalPurchaseOrder": "ZRP568930082",
"Cashier": "CHRIS",
"BuyerTPIN": "199863289426",
"BuyerName": "Inspur",
"BuyerTaxAccountName": "Western Ville",
"BuyerAddress": "Eagles Nest ",
"BuyerTel": "+5869302179940",
"OriginalInvoiceCode": null,
"OriginalInvoiceNumber":null,
"Items": [
{
"ItemId": 1,
"Description": "Fruit Drink",
"BarCode": "783692456300",
"Quantity": 8,
"UnitPrice": 2,
"Discount": 0,
"TaxLabels": [
"A",
"null"
],
"TotalAmount": 16,
"isTaxInclusive": true,
"RRP": 0
}
]
}

Open in new window



If it was on an Ms Access Form, I can achieve this by doing it this way:
 
If IsNull(Me.TaxClassB)Then
Me.TaxCassB.Visible = False
End If

Open in new window


How about where VBA is feed Json, how can we withhold Null Values so that we avoid the Null values on the Json String? I tried the code below its NOT working at all.

Dim myvar As Variant
 Tax.Add ( myvar = DLookup("TaxClassB", "QryJson", "InvoiceID =" & Me.InvoiceID & " AND ItemesID =" & CStr(i)))
    If Not IsNull(myvar) Then
        If Len(myvar) > 0 Then
            Tax.Add myvar
        End If
    End If

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technical Director
Commented:
If myvar is variant then it's initial value is empty
So use IsEmpty function