Option Compare Database
Option Explicit
Private Sub CmdSales_Click()
Dim Company As New Dictionary
Dim Json As Object
Dim data As New Dictionary
Dim transactions As Collection
Dim productlist As New Dictionary
Dim itemCount As Long
Dim i As Long
Dim item As New Dictionary
Dim items As New Collection
Set data = New Dictionary
Set productlist = New Dictionary
Set transactions = New Collection
Set Company = New Dictionary
Company.Add "Tpin", "1002623668"
Company.Add "bhfld", "00"
Company.Add "InvoiceNo", 15
Company.Add "receipt", data
data.Add "CustomerTpin", "1001102603"
data.Add "CustomerMblNo", Null
data.Add "itemList", transactions
'thedbguy@gmail.com
'12/14/2023
' '--- loop over all the items
' itemCount = Me.txtProductcount
'
' For i = 1 To itemCount
' Set item = New Dictionary
' transactions.Add item
' item.Add "ItemId", i
' item.Add "Description", DLookup("Description", "tblInvoicedetails", "[INV] =" & Me.CboInv)
' item.Add "Qty", DLookup("Qty", "tblInvoicedetails", "[INV] =" & Me.CboInv)
' item.Add "UnitPrice", DLookup("UnitPrice", "tblInvoicedetails", "[INV] =" & Me.CboInv)
'
' Next i
Dim rs As DAO.Recordset
Dim varDesc As Variant
Dim varQty As Variant
Dim varPrice As Variant
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblInvoiceDetails WHERE INV=" & Me.CboInv, dbOpenSnapshot)
With rs
Do While Not .EOF
varDesc = !Description
varQty = !Qty
varPrice = !UnitPrice
Set item = New Dictionary
transactions.Add item
item.Add "ItemId", i + 1
item.Add "Description", varDesc
item.Add "Qty", varQty
item.Add "UnitPrice", varPrice
.MoveNext
i = i + 1
Loop
.Close
End With
Set rs = Nothing
Debug.Print JsonConverter.ConvertToJson(Company, Whitespace:=3)
End Sub