Link to home
Start Free TrialLog in
Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScFlag for Zambia

asked on

Missing Values in The Code in Ms Access

Sorry all the out there I have made a mistake to close the earlier question on the  ms access vba /Json code below:

Private Sub CmdSales_Click()
Const SQL_SELECT As String = "SELECT * FROM Qry1;"

  Dim coll As New Collection
  Dim dict As Scripting.Dictionary
  Dim db As DAO.Database
  Dim rs As DAO.Recordset
  Dim fld As DAO.Field
  Set coll = New Collection
  Set db = CurrentDb
  Set rs = db.OpenRecordset(SQL_SELECT, dbOpenSnapshot)
  If Not rs.BOF And Not rs.EOF Then
    Do While Not rs.EOF
      Set dict = New Scripting.Dictionary
      For Each fld In rs.Fields
        dict.Add fld.Name, rs.Fields(fld.Name)
      Next fld

      coll.Add dict
      rs.MoveNext
    Loop
  End If

  rs.Close
  Set fld = Nothing
  Set rs = Nothing
  Set db = Nothing
  Set dict = Nothing
  MsgBox JsonConverter.ConvertToJson(coll, Whitespace:=3)
  Set coll = Nothing
End Sub

Open in new window


The value are missing I did not notice that my appology


User generated image
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

That's why i suggested Dictionary insted of Collection
Dictionary stores Key and Value.
In the key you save the FieldName and in the Value the Value of the Field....
Collection will only save 1 single value....(it also has an index but is not easy to refer to it)
I think your code can use Dictionary...SO start slowly...create a Dictionary ....insert a couple of Keys/Values and feed to the Json Converter...check if it works OK....just check the output string....make a quick and dirty example...don't feed your complete recordsource....just a small test
Points gone from previous question ... :(
How does the Json convert work?
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My recommendation is to pass the (populated) recordset into a conversion routine.  Recordsets are, basically, a collection of dictionaries (if you squint at them).
Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc

ASKER

Dear Ste5an

Thank you so much this is un believable it is done for good! what a great job!

Thank you so much once more!

Regards

Chris