I want to replace the domain functions in my MS Access project in order to improve the speed, but I seem to be failing, I have tried to use AI still waste it was retuning zero result, however the code below work very well with the domain functions any help out there will be highly appreciated.
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rst As DAO.Recordset
Dim Company As New Dictionary
Dim strData As String
Dim Json As Object
Dim data As New Dictionary
Dim transactions As Collection
Dim itemCount As Long
Dim i As Long
Dim n As Integer
Dim Z As Integer
Dim item As New Dictionary
Dim items As New Collection
Dim prm As DAO.Parameter
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("QryJson")
For Each prm In qdf.Parameters
prm = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenSnapshot, dbSeeChanges)
Set qdf = Nothing
rs.MoveFirst
Do While Not rs.EOF
Set data = New Dictionary
Set transactions = New Collection
Set Company = New Dictionary
Company.Add "tpin", Forms!FrmLogin!txtsuptpin.Value
Company.Add "bhfId", Forms!FrmLogin!txtbhfid.Value
Company.Add "cisInvcNo", rs!cisInvcNo.Value
Company.Add "orgInvcNo", Nz(rs!OrignalInvoiceNumber.Value, 0)
Company.Add "orgSdcId", Forms!FrmLogin!txtDeviceSerialNumber.Value
Company.Add "custTpin", rs!TPIN.Value
Company.Add "prcOrdCd", 0
Company.Add "custNm", rs!Company.Value
Company.Add "salesTyCd", rs!SalesType.Value
Company.Add "rcptTyCd", IIf((rs!DocCodes.Value = Null), "D", rs!DocCodes.Value)
Company.Add "pmtTyCd", rs!PaymentIDs.Value
Company.Add "salesSttsCd", "02"
Company.Add "cfmDt", rs!ActualDate.Value
Company.Add "salesDt", Format((rs!ShipDate), "yyyymmdd")
Company.Add "stockRlsDt", IIf(Len(rs!stockreleasing.Value), rs!stockreleasing.Value, Null)
Company.Add "cnclReqDt", Null
Company.Add "cnclDt", Null
Company.Add "rfdDt", Null
Company.Add "rfdRsnCd", rs!rfdRsnCd.Value
Company.Add "totItemCnt", Me.txtinternalaudit
Company.Add "taxblAmtA", Nz(Round(DSum("TaxableValue", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'A'"), 4), 0)
Company.Add "taxblAmtB", Nz(Round(DSum("TaxableValue", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'B'"), 4), 0)
Company.Add "taxblAmtC", 0
Company.Add "taxblAmtC1", Nz(Round(DSum("TaxableValue", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'C1'"), 4), 0)
Company.Add "taxblAmtC2", Nz(Round(DSum("TaxableValue", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'C2'"), 4), 0)
Company.Add "taxblAmtC3", Nz(Round(DSum("TaxableValue", "QryJson", "[InvoiceID] =" & Me.CboEsdInvoices & "And [TaxClassA] = 'C3'"), 4), 0)
Company.Add "taxblAmtD", Nz(Round(DSum("TaxableValue", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'D'"), 4), 0)
Company.Add "taxblAmtRvat", Nz(Round(DSum("TaxableValue", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'RVAT'"), 4), 0)
Company.Add "taxblAmtE", Nz(Round(DSum("TaxableValue", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'E'"), 4), 0)
Company.Add "taxblAmtF", 0
Company.Add "taxblAmtIpl1", 0
Company.Add "taxblAmtIpl2", 0
Company.Add "taxblAmtTl", Nz(Round(DSum("TLTaxable", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TourismClass] = 'TL'"), 4), 0)
Company.Add "taxblAmtEcm", 0
Company.Add "taxblAmtExeeg", 0
Company.Add "taxblAmtTot", 0
Company.Add "taxRtA", 16
Company.Add "taxRtB", 16
Company.Add "taxRtC1", 0
Company.Add "taxRtC2", 0
Company.Add "taxRtC3", 0
Company.Add "taxRtD", 0
Company.Add "taxRtE", 0
Company.Add "taxRtF", 10
Company.Add "taxRtIpl1", 5
Company.Add "taxRtIpl2", 0
Company.Add "taxRtTl", 1.5
Company.Add "taxRtEcm", 5
Company.Add "taxRtExeeg", 3
Company.Add "taxRtTot", 0
Company.Add "taxRtRvat", 16
Company.Add "taxAmtA", Nz(Round(DSum("TaxAmount", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'A'"), 4), 0)
Company.Add "taxAmtB", Nz(Round(DSum("TaxAmount", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'B'"), 4), 0)
Company.Add "taxAmtC1", 0
Company.Add "taxAmtC2", 0
Company.Add "taxAmtC3", 0
Company.Add "taxAmtD", 0
Company.Add "taxAmtC", 0
Company.Add "tlAmt", 0
Company.Add "taxAmtE", 0
Company.Add "taxAmtF", 0
Company.Add "taxAmtIpl1", 0
Company.Add "taxAmtIpl2", 0
Company.Add "taxAmtTl", Nz(Round(DSum("TLLevyTax", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TourismClass] = 'TL'"), 4), 0)
Company.Add "taxAmtEcm", 0
Company.Add "taxAmtExeeg", 0
Company.Add "taxAmtTot", 0
Company.Add "taxAmtRvat", Nz(Round(DSum("FinalTax", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'RVAT'"), 4), 0)
Company.Add "totTaxblAmt", Round(DSum("TaxableValue", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived), 4)
Company.Add "totTaxAmt", Round(DSum("TaxAmount", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived), 4) + Nz(Round(DSum("TLLevyTax", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TourismClass] = 'TL'"), 4), 0)
Company.Add "totAmt", DSum("ActualPricing", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived) + Nz(Round(DSum("Taxable", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And [TurnoverClass] = 'TOT'"), 4), 0)
Company.Add "prchrAcptcYn", "N"
Company.Add "remark", rs!TheNotes.Value
Company.Add "regrId", Forms!FrmLogin!txtpersoning.Value
Company.Add "regrNm", Forms!FrmLogin!txtpersoning.Value
Company.Add "modrId", Forms!FrmLogin!txtpersoning.Value
Company.Add "modrNm", Forms!FrmLogin!txtpersoning.Value
Company.Add "saleCtyCd", "1"
Company.Add "lpoNumber", rs!LocalPurchaseOrder.Value
Company.Add "currencyTyCd", rs!Moneytype.Value
Company.Add "exchangeRt", rs!FCRate.Value
Company.Add "destnCountryCd", IIf((rs!CountryDestination.Value = Null), "", rs!CountryDestination.Value)
Company.Add "dbtRsnCd", rs!DebitNoteReason.Value
Company.Add "nvcAdjustReason", rs!TheNotes.Value
Company.Add "itemList", transactions
'--- loop over all the items
itemCount = Me.txtinternalaudit
For i = 1 To itemCount
Set item = New Dictionary
transactions.Add item
item.Add "itemSeq", i
item.Add "itemCd", DLookup("itemCd", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i))
item.Add "itemClsCd", DLookup("itemClsCd", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i))
item.Add "itemNm", DLookup("ProductName", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i))
item.Add "bcd", Null
item.Add "pkgUnitCd", "NT"
item.Add "pkg", 1
item.Add "qtyUnitCd", "U"
item.Add "qty", Nz(Round(DLookup("Qty", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
item.Add "prc", Nz(Round(DLookup("UnitPrice", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
item.Add "rrp", Nz(Round(DLookup("RRP", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
item.Add "splyAmt", Nz(Round(DLookup("FinalPricings", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
item.Add "dcRt", 0
item.Add "dcAmt", 0
item.Add "isrccCd", ""
item.Add "isrccNm", ""
item.Add "isrcRt", 0
item.Add "isrcAmt", 0
item.Add "vatCatCd", DLookup("TaxClassA", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i))
item.Add "iplCatCd", Null
item.Add "tlCatCd", IIf((rs!TourismClass.Value <> ""), "TL", Null)
item.Add "exciseCatCd", Null
item.Add "vatTaxblAmt", Nz(Round(DLookup("TaxableValue", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
item.Add "vatAmt", Nz(Round(DLookup("TaxAmount", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
item.Add "exciseTaxblAmt", 0
item.Add "tlTaxblAmt", Nz(Round(DLookup("TLTaxable", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
item.Add "iplTaxblAmt", 0
item.Add "iplAmt", 0
item.Add "tlAmt", Nz(Round(DLookup("TLLevyTax", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
item.Add "exciseTxAmt", 0
item.Add "totAmt", Nz(Round(DLookup("ActualPricing", "QryJson", "[InvoiceID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
strData = JsonConverter.ConvertToJson(Company, Whitespace:=3)
rs.MoveNext
Next
Loop