Albert D. Kallal
Active member
- Local time
- Today, 10:39
- Joined
- Jun 11, 2009
- Messages
- 107
A few things - but just a quick look here at what we have so far?
First, don't use on-current - avoid if possible.
Next up, a goToControl is placed/moved to the sub form.
I suggest to NOT do this.
So, keep/write ALL of the code in the main form - don't use the "UI" to set focus in sub form.
You trying to do "data processing" by using the UI. The UI is for the "user", not data procesisng code!
If you start writing a bunch of UI code based on setfocus, and updating text boxes?
That is going to be flicker city!!!
Worse, any kind of timer control etc. - again going to cause issues!
Hence, do NOT do the insert by filing out controls into the sub form - but insert into a recordset.
And BETTER is to use recordSetClone, not the recordset
Why?
Because the forms reocrdset is tied to the UI, and recordset clone is NOT!!!!
So, get/grab/use the existing sub form recordset
The above is good "general" advice here.
Try to "avoid" using the "UI" for database operations. So, things like setting focus from the main form to sub form. and then moving the sub form to a new reocrd!!! - And all the while the main Access processor thread is "stacking" up all kinds of re-draw events, set focus events into that "behind the scenes UI thread update system.
No matter how you spin this?
It's going to be junkiy....
So, new logic:
Scan occures in main form.
Process the scan data, insert into the sub form recordset (recordset clone) - NOT the UI!!!
do a subform.requrey to show the new row you inserted (via code directly into hte table), and turns out you already have that!!!
Then, consider a setfocus back to the control that holds/expects the scan.
I assume the scanner does either a tab, or a enter key for you - make sure there is at least one other control on that main form to receive the focus after that tab key (hit by scanner for you) exists to accept the focus...
So, quick glance at the code, some "air code" here?
First up, mID -- that conflicts with Mid() - reserved word - hence use me!mID....
AIR code warning here....
Try the above approach.
So, the lesson of the day?
Don't use the UI for data processing - write such processing - you eliminate boatloads of screen flicker and updates as a nice bonus...
When possible, and adding data?
Use RecordSetClone in place of RecordSet - I can expand on why this is a better/good design approach..
R
Albert
First, don't use on-current - avoid if possible.
Next up, a goToControl is placed/moved to the sub form.
I suggest to NOT do this.
So, keep/write ALL of the code in the main form - don't use the "UI" to set focus in sub form.
You trying to do "data processing" by using the UI. The UI is for the "user", not data procesisng code!
If you start writing a bunch of UI code based on setfocus, and updating text boxes?
That is going to be flicker city!!!
Worse, any kind of timer control etc. - again going to cause issues!
Hence, do NOT do the insert by filing out controls into the sub form - but insert into a recordset.
And BETTER is to use recordSetClone, not the recordset
Why?
Because the forms reocrdset is tied to the UI, and recordset clone is NOT!!!!
So, get/grab/use the existing sub form recordset
The above is good "general" advice here.
Try to "avoid" using the "UI" for database operations. So, things like setting focus from the main form to sub form. and then moving the sub form to a new reocrd!!! - And all the while the main Access processor thread is "stacking" up all kinds of re-draw events, set focus events into that "behind the scenes UI thread update system.
No matter how you spin this?
It's going to be junkiy....
So, new logic:
Scan occures in main form.
Process the scan data, insert into the sub form recordset (recordset clone) - NOT the UI!!!
do a subform.requrey to show the new row you inserted (via code directly into hte table), and turns out you already have that!!!
Then, consider a setfocus back to the control that holds/expects the scan.
I assume the scanner does either a tab, or a enter key for you - make sure there is at least one other control on that main form to receive the focus after that tab key (hit by scanner for you) exists to accept the focus...
So, quick glance at the code, some "air code" here?
First up, mID -- that conflicts with Mid() - reserved word - hence use me!mID....
AIR code warning here....
Code:
Public Sub txtProductCode_AfterUpdate()
Dim lngProdID As Long
Dim sReturn$ ' as string
Dim varValue As Variant
Dim rstSubFormData As DAO.Recordset
If Not (IsNull(Me!ID)) Then
Set rstSubFormData = Me![sfrmPosLineDetails Subform].Form.RecordsetClone
With rstSubFormData
.AddNew
![ProductID] = Mid
![QtySold] = 1
sReturn = DLookup("ProductName & '|' & vatCatCd & '|' & dftPrc & '|' & VAT", _
"tblProducts", _
"BarCode = '" & Me.txtProductCode & "'")
varValue = Split(sReturn, "|")
![ProductName] = varValue(0)
![TaxClassA] = varValue(1)
![SellingPrice] = varValue(2)
![Tax] = varValue(3)
![RRP] = 0
.Update
End With
End If
Me.sfrmPosLineDetails_Subform.Requery
' clean up main form controls - emptry, ready for next scan
Me.txtProductCode = Null
Me.txtProductCode.SetFocus
End Sub
Try the above approach.
So, the lesson of the day?
Don't use the UI for data processing - write such processing - you eliminate boatloads of screen flicker and updates as a nice bonus...
When possible, and adding data?
Use RecordSetClone in place of RecordSet - I can expand on why this is a better/good design approach..
R
Albert