VBA Code error on the counter

nectorch

Member
Local time
Today, 02:23
Joined
Aug 4, 2021
Messages
45
I'm getting an error on the counter section whenever i run the code below , where is the problem:

Code:
Public Sub CmdSendingBomFineshedProd_Click()
On Error Resume Next
Dim Cancel As Integer
If IsNull(Me.CboIssue) Then
Beep
MsgBox "Please Select the Product name you want to transfer data to smart invoice", vbInformation, "Wrong data"
Cancel = True
Exit Sub
End If
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Company As New Dictionary
Dim strData As String
Dim n As Long
Dim Json As Object
Dim data As New Dictionary
Dim transactions As Collection
Dim itemCount As Long
Dim i As Long
Dim item As New Dictionary
Dim prm As DAO.Parameter
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("QryBOMFinishedProduct")

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 "sarNo", rs!SarNumber.Value
        Company.Add "orgSarNo", 0
        Company.Add "regTyCd", rs!regTyCd.Value
        Company.Add "sarTyCd", rs!sarTyCd.Value
        Company.Add "custTpin", "1000000000"
        Company.Add "custNm", "Walk In Customer"
        Company.Add "custBhfId", rs!custbhfld.Value
        Company.Add "ocrnDt", Format((rs!IssueDate.Value), "yyyymmdd")
        Company.Add "totItemCnt", Me.txtinternalaudit
        Company.Add "totTaxblAmt", Round(DSum("taxblAmt", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue), 4)
        Company.Add "totTaxAmt", Round(DSum("taxAmt", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue), 4)
        Company.Add "totAmt", Round(DSum("totAmt", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue), 4)
        Company.Add "remark", "Okay"
        Company.Add "regrNm", Forms!frmLogin!txtpersoning.Value
        Company.Add "regrId", Forms!frmLogin!txtpersoning.Value
        Company.Add "modrNm", Forms!frmLogin!txtpersoning.Value
        Company.Add "modrId", Forms!frmLogin!txtpersoning.Value
        Company.Add "itemList", transactions
              
    '--- loop over all the items
        itemCount = Me.txtExternalAudit
        
        For i = 1 To itemCount
            Set item = New Dictionary
            transactions.Add item
            item.Add "itemSeq", i
            item.Add "itemCd", DLookup("itemCd", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue)
            item.Add "itemClsCd", DLookup("itemClsCd", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue)
            item.Add "itemNm", DLookup("ProductName", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue)
            item.Add "pkgUnitCd", DLookup("pkgUnitCd", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue)
            item.Add "qtyUnitCd", DLookup("qtyUnitCd", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue)
            item.Add "pkg", DLookup("Qty", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue)
            item.Add "qty", DLookup("Qty", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue)
            item.Add "totDcAmt", 0
            item.Add "prc", Round(DLookup("dftPrc", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue), 4)
            item.Add "splyAmt", Round(DLookup("dftPrc", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue), 4)
            item.Add "taxblAmt", Round(DLookup("taxblAmt", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue), 4)
            item.Add "vatCatCd", DLookup("vatCatCd", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue)
            item.Add "taxAmt", Round(DLookup("taxAmt", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue), 4)
            item.Add "totAmt", Round(DLookup("totAmt", "QryBOMFinishedProduct", "[SlipID] =" & Me.CboIssue), 4)


Error in a picture


Code error.png

The Json part is coming okay see the dump

Code:
{
   "tpin": "1000000453",
   "bhfId": "000",
   "sarNo": 1511,
   "orgSarNo": 0,
   "regTyCd": "M",
   "sarTyCd": "05",
   "custTpin": "1000000000",
   "custNm": "Walk In Customer",
   "custBhfId": "000",
   "ocrnDt": "20240908",
   "totItemCnt": 2,
   "totTaxblAmt": 1487.069,
   "totTaxAmt": 237.931,
   "totAmt": 1725,
   "remark": "Okay",
   "regrNm": "Admin Manager",
   "regrId": "Admin Manager",
   "modrNm": "Admin Manager",
   "modrId": "Admin Manager",
   "itemList": [
      {
         "itemSeq": 1,
         "itemCd": "ZM2EAEA000000",
         "itemClsCd": "23181510",
         "itemNm": "SPECIAL PIE",
         "pkgUnitCd": "EA",
         "qtyUnitCd": "EA",
         "pkg": 23,
         "qty": 23,
         "totDcAmt": 0,
         "prc": 75,
         "splyAmt": 75,
         "taxblAmt": 1487.069,
         "vatCatCd": "A",
         "taxAmt": 237.931,
         "totAmt": 1725
      }
   ]
}
 
1. You are moving the same value to both pkg and qty
2. Domain functions inside a loop or a query are extremely inefficient.
3. This is not a process which using a Dictionary would help with. You should be moving the JSON data to a table directly.

None of these has anything to do with your error but might induce you to rethink your code.
 
1. It seems like the error message indicates that there’s an issue with the parameters in your request.
2. Your string might be correct, but it doesn’t necessarily mean that it’s formatted in a way the server can process.
3. The code you posted is incomplete.
4. Your code does not include the actual request, it's just a part of the code you used to build the string.
5. We don't know what the server needs to process your request.
 
In the JSON data I see:
Code:
"totItemCnt": 2,
And the "ItemList" array contains only one item instead of 2
 
Last edited:
Thank you so much Edgar!

1. It seems like the error message indicates that there’s an issue with the parameters in your request.

You seem to have a very clear understanding of this error message, I need to concentrate on this point, I will be back with the results tonight.
 
You don't show the complete code for CmdSendingBomFineshedProd_Click() in your original post.

Also, why not open a recordset returning a single row from QryBOMFinishedProduct instead of using a DLookup() for each individual field? It would be much faster.
 

Users who are viewing this thread

Back
Top Bottom