For the first time I encountered an error while using Do until loop on a simple database but on the more complex database its working okay , its very embarrassing to have such issues sure.
Where do I go wrong?
The error only occurs when I use the on click but not on compiling , see the picture attached and database
Where do I go wrong?
The error only occurs when I use the on click but not on compiling , see the picture attached and database
Code:
Option Compare Database
Option Explicit
Private Sub CmdSales_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim Company As New Dictionary
Dim data As New Dictionary
Dim transactions As Collection
Dim itemCount As Long
Dim i As Long
Dim item As New Dictionary
Set data = New Dictionary
Set transactions = New Collection
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 Until rs.EOF
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
Company.Add "itemList", transactions
'--- 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", "QryJson", "[INV] =" & Me.CboInv & " And ItemID = " & CStr(i))
item.Add "Qty", DLookup("Qty", "QryJson", "[INV] =" & Me.CboInv & " And ItemID = " & CStr(i))
item.Add "UnitPrice", DLookup("UnitPrice", "QryJson", "[INV] =" & Me.CboInv & " And ItemID = " & CStr(i))
Next i
Debug.Print JsonConverter.ConvertToJson(Company, Whitespace:=3)
rs.Close
Loop
Set rs = Nothing
Set db = Nothing
Set transactions = Nothing
Set item = Nothing
Set qdf = Nothing
Set prm = Nothing
End Sub