Make code Shorter

stoicy

Registered User.
Local time
Today, 08:47
Joined
Feb 16, 2019
Messages
40
Hello Everybody




is it possible to make this code shorter!!


Code:
[Forms]![frmOrder]![frmOrderDetails].[Form]![AvaQu] = [Forms]![frmOrder]![frmOrderDetails].[Form]![AvaQu] - [Forms]![frmOrder]![frmOrderDetails].[Form]![ProQu]
Exit Sub
[Forms]![frmOrder]![frmOrderDetails].[Form]![AvaQu] = [Forms]![frmOrder]![frmOrderDetails].[Form]![AvaQu] + [Forms]![frmOrder]![frmOrderDetails].[Form]![RetQu]


frmOrder = Main Form
frmOrderDetails = Sub Form
AvaQu = Avaliable quantity of product in store
ProQu = Reqursted Quantity (Sales)
RetQu = Returned Quantity (Sales)




Thank you for usual support
 
Is this in the main form, the sub form, or some where else?
 
Is this in the main form, the sub form, or some where else?
Sorry

I put it in sub form after update

I don't know if it is the right place

Sent from my SM-N900V using Tapatalk
 
If your repeat things, use a variable

Code:
Dim myFrm as access.form 'if frmorder is the current form then
set myFrm = me.frmOrderDetails.form
myFrm.avaqu = myfrm.avaqu-myfrm.proqu
exit sub
myfrm.avaqu = myfrm.avaqu + myfrm.retqu
 
If your repeat things, use a variable

Code:
Dim myFrm as access.form 'if frmorder is the current form then
set myFrm = me.frmOrderDetails.form
myFrm.avaqu = myfrm.avaqu-myfrm.proqu
exit sub
myfrm.avaqu = myfrm.avaqu + myfrm.retqu
I put that code but an error message appears saying "Compile error Method or data member not found"

Sent from my SM-N900V using Tapatalk
 
I am basing this on some assumptions without seeing all the code, and not doing this in vba. Please take the concept and error checked what I typed. Where does the code break?
 
Sorry I am not good with codes
See attached pic
69c1acb37a4d1e288bf87db1a8899012.jpg


Sent from my SM-N900V using Tapatalk
 
It appears that frmOrderDetails is not a subform control on the current form. If frmOrders is not the current from where the code is called then you cannot use Me. It would have to reference frmOrders

set myFrm = Forms!frmOrder.frmOrderDetails.Form
 
you could try

Code:
with [Forms]![frmOrder]![frmOrderDetails].[Form]
    ![AvaQu] =![AvaQu] - ![ProQu]
end with
Exit Sub
 
Also not working
d850b6be63fbe083c8434933b6f90a25.jpg


Sent from my SM-N900V using Tapatalk
 
Why not just write it as CJ_London posted?
 
there is an assumption that your original 'long' code works - does it? and if not what error do you get? And what error are you getting with my suggestion?

I ask because normally you would use .[AvaQu] rather than ![AvaQu]


FYI most computers now have a 'snipping tool' to take screen shots of part of the screen - you might find that a lot easier than photographing it. Just click on the windows start button, bottom left of the screen and start typing 'snipping tool'
 
there is an assumption that your original 'long' code works - does it? and if not what error do you get? And what error are you getting with my suggestion?

I ask because normally you would use .[AvaQu] rather than ![AvaQu]


FYI most computers now have a 'snipping tool' to take screen shots of part of the screen - you might find that a lot easier than photographing it. Just click on the windows start button, bottom left of the screen and start typing 'snipping tool'
Yes my code us working but through button.

I thought it will be shorter and to work after update in the subform.


Sent from my SM-N900V using Tapatalk
 
I'll guess that there have been 2 forms created and saved as frmOrder and frmOrderDetails. Check the name of the subForm control in Properties in design mode. It will probably be Childx but it may have been renamed.

It's necessary to refer to the subform control name ie
Code:
forms!frmOrder.Childx.form.[AvaQu]
 

Users who are viewing this thread

Back
Top Bottom