The program below works very fine no errors whatsoever; we have also made sure that all the tables have primary keys and foreign keys to easy searching records. However, someone whispered to me yesterday that the domain functions included in your VBA will be slowing the speed and the solution to increase the speed of the program further is to replace them.
That is where I have a challenge because first of all if you check the VBA below, I'm opening the MS Access query called QryJsonPos001 which essentially is the provider of all the required records or fields for the program, now the challenge is that the required line items need to be picked by using TWO PARAMETERS without using those parameters , see below, the VBA code will repeating one line several times.
That is the reason why you can see that I'm using Dlookup and Dsum to accommodate the two parameters.
Requirements
Using this Set rs = qdf.OpenRecordset(dbOpenSnapshot, dbSeeChanges) how do I bring in the two parameters into VBA to avoid using domain functions, for example this code works because it does not require parameters "Company.Add "cisInvcNo", rs!cisInvcNo.Value"
Questions
Now using the same concept "Company.Add "cisInvcNo", rs!cisInvcNo.Value" now how can we include the two parameters shown with the domain functions below with rs record set?
MS Access VBA with open recordset
Actual query "QryJsonPos001"with fields just to show you for reference purpose only
That is where I have a challenge because first of all if you check the VBA below, I'm opening the MS Access query called QryJsonPos001 which essentially is the provider of all the required records or fields for the program, now the challenge is that the required line items need to be picked by using TWO PARAMETERS without using those parameters , see below, the VBA code will repeating one line several times.
That is the reason why you can see that I'm using Dlookup and Dsum to accommodate the two parameters.
Requirements
Using this Set rs = qdf.OpenRecordset(dbOpenSnapshot, dbSeeChanges) how do I bring in the two parameters into VBA to avoid using domain functions, for example this code works because it does not require parameters "Company.Add "cisInvcNo", rs!cisInvcNo.Value"
Questions
Now using the same concept "Company.Add "cisInvcNo", rs!cisInvcNo.Value" now how can we include the two parameters shown with the domain functions below with rs record set?
Code:
Company.Add "taxblAmtA", Nz(Round(DSum("TaxableValue", "QryJsonPos001", "[ItemSoldID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'A'"), 4), 0)
For i = 1 To itemCount
Set item = New Dictionary
transactions.Add item
item.Add "itemSeq", i
item.Add "qty", Nz(Round(DLookup("QtySold", "QryJsonPos001", "[ItemSoldID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
MS Access VBA with open recordset
Code:
Public Sub Cmdsandboxwriting_Click()
On Error Resume Next
Call CmdCmdTotalClasses_Click
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("QryJsonPos001")
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 "cisInvcNo", rs!cisInvcNo.Value
Company.Add "taxblAmtA", Nz(Round(DSum("TaxableValue", "QryJsonPos001", "[ItemSoldID] =" & Me.txtJsonReceived & "And [TaxClassA] = 'A'"), 4), 0)
For i = 1 To itemCount
Set item = New Dictionary
transactions.Add item
item.Add "itemSeq", i
item.Add "qty", Nz(Round(DLookup("QtySold", "QryJsonPos001", "[ItemSoldID] =" & Me.txtJsonReceived & "And ItemesID =" & CStr(i)), 4), 0)
Actual query "QryJsonPos001"with fields just to show you for reference purpose only
Code:
SELECT tblproducts.productname,
tblproducts.productid,
( Iif(([taxclassa]<>"b"), ((([qty]*[sellingprice]))), 0)
+ Iif(([taxclassa]="b"), ((([qty]*[tblposlinedetails].[rrp]))), 0) )
AS
TotalAmount,
( ( Iif(( [sellingprice] > [tblposlinedetails].[rrp] ), ( ((
( [sellingprice] ) * [tax] * 1 )) / 1.16 ), ( (( (
[tblposlinedetails].[rrp] ) * [tax] * 1 )) / 1.16 )) ) * [qtysold] )
AS
FinalTax,
( Iif(( [taxclassa] = "tv" ), ( ( ( [sellingprice] ) / ( 1 + [turnovertax] ) ) *
[qtysold] ), ( Iif((
[tblposlinedetails].[rrp] > [sellingprice] ), (( (
( [tblposlinedetails].[rrp] ) /
( 1 + (
Nz([tax], 0) + Nz([tourismlevy], 0) ) ) ) * [qtysold] )), (
(
( ( [sellingprice] ) / ( 1 + ( Nz([tax], 0) + Nz([tourismlevy], 0) ) ) ) * [qtysold] ))) )) ) AS TaxableValue,
Iif(( [finaltax] IS NOT NULL ), [taxablevalue], NULL)
AS TaxableAB,
Round(( Nz([finaltax], 0) + Nz([taxablevalue], 0) ), 2)
AS TaxInclusive,
( Iif(([taxclassa]<>"b"), ((([qtysold]*[sellingprice]))), 0)
+ Iif(([taxclassa]="b"), ((([qtysold]*[tblposlinedetails].[rrp]))), 0) )
AS
SupplierAmount,
( (( Iif(( [taxclassa] = "tv" ), ( ( ( [sellingprice] ) / ( 1 + [turnovertax] )
)
*
[qtysold] ), ( Iif((
[tblposlinedetails].[rrp] > [sellingprice] ), (( (
( [tblposlinedetails].[rrp] ) /
( 1 + (
Nz([tax], 0) + Nz([tourismlevy], 0) ) ) ) * [qtysold] )), (
(
( ( [sellingprice] ) / ( 1 + ( Nz([tax], 0) + Nz([tourismlevy], 0) ) ) ) * [qtysold] ))) )) )) * 0 ) AS DiscountValue,
tblproducts.itemclscd,
tblproducts.itemcd,
tblproducts.barcode,
tblposstockssold.itemsoldid,
tblposlinedetails.taxclassa,
tblposstockssold.thenotes,
tblposstockssold.cashier,
tblposlinedetails.qtysold,
tblposlinedetails.sellingprice,
tblposstockssold.orignalinvoicenumber,
tblposstockssold.orignalinvoicecode,
( (( ( [tblposlinedetails].[rrp] ) * [tax] * 1 )) / 1.16 )
AS RRPrice,
tblposlinedetails.tax,
Nz(0, 0)
AS prcOrdCd,
""
AS prcOrdCdss,
Iif(( [doccodes] = "s" ), Nz([prcordcd], 0), [prcordcdss])
AS NewprcOrdCd,
tbldocuments.doccodes,
Format((( Iif(( [doccodes] = "s" ), Now(), NULL) )), "yyyymmddhhnnss")
AS
stockreleasing,
Format(( Now() ), "yyyymmddhhnnss")
AS ActualDate,
Iif(( [doccodes] = "s" ), "n", "y")
AS prchrAcptcYn,
Iif(( [doccodes] = "s" ), NULL, "05")
AS rfdRsnCding,
tbldocuments.doctype,
tblposstockssold.posdate,
tblposstockssold.bhfid,
tblposstockssold.suptpin,
tbldocuments.docid,
( Iif(( [doccodes] = "r" ), ( [qtysold] *- 1 ), [qtysold]) )
AS Qty,
[tblposstockssold].[itemsoldid] & "kzvzrn2571"
AS cisInvcNo,
tblposstockssold.refundreason,
tblposstockssold.fcrate,
tblposstockssold.currencytype,
tblposstockssold.rfdrsncd,
tblposstockssold.actionrefundtype,
tblposstockssold.actiondebitnotereason,
tblposstockssold.debitnotereason,
tblposstockssold.selectcodesale,
tblposstockssold.salescode,
tblposstockssold.rejectedstatus,
tblposstockssold.inncancel,
tblposlinedetails.itemesid
FROM (tblposstockssold
INNER JOIN tbldocuments
ON tblposstockssold.docid = tbldocuments.docid)
INNER JOIN (tblproducts
INNER JOIN tblposlinedetails
ON tblproducts.productid =
tblposlinedetails.productid)
ON tblposstockssold.itemsoldid = tblposlinedetails.itemsoldid
WHERE (
( ( tblposstockssold.itemsoldid ) = [forms] ! [frmposstockssold] ! [cboesdss] )
AND ( ( tblposstockssold.inncancel ) IS NULL ) )
ORDER BY tblposlinedetails.itemesid;
Last edited: