Receiving Certified Data in Json Format in Ms Access

Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc used Ask the Experts™
Sorry people here;

 I have come again for clarifications on receiving the data from the machine RS 232 using Ms Access App. This week we have started testing the new machines we ordered last month to be used to account for Value added tax (VAT) and transmitting the invoices details one by one a time  to the taxman server. Sending is not an issue all is okay , but receiving certified data from the server , we are finding some challenges ,the received data is supposed to pasted in the table called tblInvoice , but its empty no data after processing.

I have gone through the code I cannot spot any error , neither are there any errors after processing, see below:

Receiving Code from RS 232

Private Sub CmdReadReceivedJson_Click()
Dim DataRead As String
  Dim DataObject As Object
  On Error GoTo Err_Handler

  If ReadDataFromSerialDevice(DataRead, 4) Then
    ' Call to JSON library to parse it.
    Set DataObject = ParseJson(DataRead)
    StoreData DataObject
    MsgBox "Data have written in the contact table", vbExclamation, "Please proceed"
    Set DataObject = Nothing
  End If
Exit Sub
Resume Exit_CmdReadReceivedJson_Click
End Sub

Private Function ReadDataFromSerialDevice(ByRef ADataRead As String, APortID As Long) As Boolean

  Dim lngStatus As Long
  Dim strData As String
  Dim PortID As Integer
  Dim intPortID As Integer

  ReadDataFromSerialDevice = False
  lngStatus = CommRead(PortID, strData, 14400)
  If lngStatus > 0 Then
    ADataRead = strData
    ReadDataFromSerialDevice = True
  End If

  lngStatus = CommSetLine(intPortID, LINE_RTS, False)
  lngStatus = CommSetLine(intPortID, LINE_DTR, False)
  ' Close communications.
    Call CommClose(intPortID)
End Function

Open in new window

Code for storing data into table tblInvoice

Private Sub StoreData(ADataObject As Object)

  Dim db As DAO.Database
  Dim rs As DAO.Recordset
  Dim item As Object

  Set db = CurrentDb
  Set rs = db.OpenRecordset("tblInvoice")
  For Each item In ADataObject
            rs![VAT] = item("TPIN")
            rs![TaxpayerName] = item("TaxpayerName")
            rs![Address] = item("Address")
            rs![Time] = item("Time")
            rs![TerminalID] = item("TerminalID")
            rs![InvoiceCode] = item("InvoiceCode")
            rs![InvoiceNumber] = item("InvoiceNumber")
            rs![Code] = item("Code")
            rs![COM] = item("COM")
            rs![Operator] = item("Operator")
            rs![Taxlabel] = item("TaxItems")("TaxLabel")
            rs![CategoryName] = item("TaxItems")("CategoryName")
            rs![Rate] = item("TaxItems")("Rate")
            rs![TaxAmount] = item("TaxItems")("TaxAmount")
            rs![VerificationUrl] = item("TaxItems")("VerificationUrl")
  Next item

  Set rs = Nothing
  Set db = Nothing

End Sub

Open in new window

Expected data from the machine in Json format

“VAT”: “1002560”, 
“TaxpayerName”: “Nector”, 
“Addreess”: “West transvel”, 
“Time”: “20190101203450”, 
“TerminalID”: “55100000065”, 
“InvoiceCode”: “11896180301ZSD”, 
“InvoiceNumber”: “KR98078896”, 
“Code”: “11298303SDRT560039SR”, 
“COM”: “786390356548855”, 
“Operator”: “BELVIEW”, 
“TaxItems”: [ 
“TaxLabel”: “D”, 
“CategoryName”: “Standard Rate”, 
“Rate”: 0.20, 
“TaxAmount”: 80.61 
“TaxLabel”: “C”, 
“CategoryName”: “Standard”, 
“Rate”: 0.18, 
“TaxAmount”: 36.77 

Open in new window

Could it be the storing code itself?????????


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer

Put  a breakpoint at this line and check if you actually get Data
ADataRead = strData

Open in new window

Also put  a 2nd breakpoint to see
Set DataObject = ParseJson(DataRead)

Open in new window

that the Dataobject is populated...(right click add watch)
Sorry the table was incorrect , the correct table is tblEfdReceipts

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial