Make code Shorter (1 Viewer)

stoicy

Registered User.
Local time
Today, 19:22
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
 

Mark_

Longboard on the internet
Local time
Today, 12:22
Joined
Sep 12, 2017
Messages
2,111
Is this in the main form, the sub form, or some where else?
 

stoicy

Registered User.
Local time
Today, 19:22
Joined
Feb 16, 2019
Messages
40
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
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:22
Joined
May 21, 2018
Messages
8,527
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
 

stoicy

Registered User.
Local time
Today, 19:22
Joined
Feb 16, 2019
Messages
40
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
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:22
Joined
May 21, 2018
Messages
8,527
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?
 

stoicy

Registered User.
Local time
Today, 19:22
Joined
Feb 16, 2019
Messages
40
Sorry I am not good with codes
See attached pic


Sent from my SM-N900V using Tapatalk
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:22
Joined
May 21, 2018
Messages
8,527
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
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:22
Joined
Feb 19, 2013
Messages
16,607
you could try

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

stoicy

Registered User.
Local time
Today, 19:22
Joined
Feb 16, 2019
Messages
40
Also not working


Sent from my SM-N900V using Tapatalk
 

stoicy

Registered User.
Local time
Today, 19:22
Joined
Feb 16, 2019
Messages
40
you could try

Code:
with [Forms]![frmOrder]![frmOrderDetails].[Form]
    ![AvaQu] =![AvaQu] - ![ProQu]
end with
Exit Sub
OK I will see now

Sent from my SM-N900V using Tapatalk
 

stoicy

Registered User.
Local time
Today, 19:22
Joined
Feb 16, 2019
Messages
40
you could try

Code:
with [Forms]![frmOrder]![frmOrderDetails].[Form]
    ![AvaQu] =![AvaQu] - ![ProQu]
end with
Exit Sub
This error see pic


Sent from my SM-N900V using Tapatalk
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:22
Joined
Sep 21, 2011
Messages
14,273
Why not just write it as CJ_London posted?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:22
Joined
Feb 19, 2013
Messages
16,607
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'
 

stoicy

Registered User.
Local time
Today, 19:22
Joined
Feb 16, 2019
Messages
40
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
 

Cronk

Registered User.
Local time
Tomorrow, 05:22
Joined
Jul 4, 2013
Messages
2,772
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

Top Bottom