Calculate Total (1 Viewer)

Minty

AWF VIP
Local time
Today, 18:48
Joined
Jul 26, 2013
Messages
10,371
I would have thought adding some Me. would help, and that can be simplified to

Me.Mass.Enabled = Me.MassRequired
 

Gismo

Registered User.
Local time
Today, 20:48
Joined
Jun 12, 2017
Messages
1,298
I would have thought adding some Me. would help, and that can be simplified to

Me.Mass.Enabled = Me.MassRequired
Yeh agee

Still not working though

Private Sub Form_Current()
If MassRequired = True Then
Me.Mass.Enabled = True
Else
Me.Mass.Enabled = False
End If
End Sub

And the code you advise wont work, when massrequired = true, control should be active
If my part required a mass = massrequired true, then die control will me made inactive by true

Correct?
 

Minty

AWF VIP
Local time
Today, 18:48
Joined
Jul 26, 2013
Messages
10,371
No - wrong way round, look at your IF statement.
Enabled = True means it's working
Enabled = False means it's not working, ergo

If Me.MassRequired = True THEN Me.Mass Enabled = True
If Me.MassRequired = False THEN Me.Mass Enabled = False

If that's not working then have you got option explicit at the top of your code, because something isn't right with the names?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:48
Joined
May 21, 2018
Messages
8,529
Can you post a sample of your db?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:48
Joined
May 21, 2018
Messages
8,529
I would have thought adding some Me. would help, and that can be simplified to
Me.Mass.Enabled = Me.MassRequired
Although using Me is often very helpful in clarifying your code and bringing up intellisense, in truth it is rarely required in a form/report module.
Any property of a form is accessible without the Me keyword so you can simply write the control name or field name or other property.
Mass.enabled is the same as Me.Mass.enabled
Same principle as Application
I never seen anyone write
Application.Docmd
But that is the full qualifier

@Gismo,
Also I am guessing you also need to put the code in the after update of the MassRequired
Code:
Private Sub Form_Current()
 EnableDisableMass
End Sub

Private Sub EnableDisableMass()
  Me.Mass.Enabled = Me.MassRequired
  Me.Mass.TabStop = Me.MassRequired
End Sub

Private Sub MassRequired_AfterUpdate()
 EnableDisableMass
End Sub

Works perfectly fine for me.
 

Attachments

  • EnableDisableMass.accdb
    448 KB · Views: 85

June7

AWF VIP
Local time
Today, 09:48
Joined
Mar 9, 2014
Messages
5,473
And what effect are you getting? Can use Conditional Formatting to enable/disable textbox or combobox.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:48
Joined
May 21, 2018
Messages
8,529
Can use Conditional Formatting to enable/disable textbox or combobox.
Oh yeah, I forgot that enabling can be done using conditional formatting too. However, the demo also demonstrates disabling/enabling the tab stop.
 

Gismo

Registered User.
Local time
Today, 20:48
Joined
Jun 12, 2017
Messages
1,298
Although using Me is often very helpful in clarifying your code and bringing up intellisense, in truth it is rarely required in a form/report module.
Any property of a form is accessible without the Me keyword so you can simply write the control name or field name or other property.
Mass.enabled is the same as Me.Mass.enabled
Same principle as Application
I never seen anyone write
Application.Docmd
But that is the full qualifier

@Gismo,
Also I am guessing you also need to put the code in the after update of the MassRequired
Code:
Private Sub Form_Current()
EnableDisableMass
End Sub

Private Sub EnableDisableMass()
  Me.Mass.Enabled = Me.MassRequired
  Me.Mass.TabStop = Me.MassRequired
End Sub

Private Sub MassRequired_AfterUpdate()
EnableDisableMass
End Sub

Works perfectly fine for me.
Hi,

Please see my DB
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:48
Joined
Feb 19, 2002
Messages
43,275
Unless there is some reason you want to track the weight for something prepackaged, you would just need quantity and UOM. If you want to round up, that becomes a much bigger problem to convert g to kg for example. So if the UOM is g, the qty could be 2000. If the UOM is each, the qty would be 1. The price would be by the UOM. So if each is $9.99 (for 10 oz) but if you buy it by the oz, then it would be .999 per oz.
 

June7

AWF VIP
Local time
Today, 09:48
Joined
Mar 9, 2014
Messages
5,473
When a control is disabled, it cannot receive focus so setting TabStop No is redundant.
 

Gismo

Registered User.
Local time
Today, 20:48
Joined
Jun 12, 2017
Messages
1,298
Untested
Code:
iif([currencyField] = "UGX", nz([mass],1) * nz([quantity],1) *[UnitPrice], nz([mass],1) * nz([quantity],1) *[UnitPrice] * [Exchange])

Nz([Mass],1) returns 1 if null else the value for mass
Hi,

I need to add below to the formula but this once is quite a puzzle for me
Could you please assist with the contention

If Currency = UGX and mass required = false then Qty * Unit price
If Currency = UGX and mass required = true then Mass * Unit price

If Currency <> UGX and mass required = false then Qty * Unit price * Exchange rate
If Currency <> UGX and mass required = true then Mass * Unit Price * Exchange rate
 

June7

AWF VIP
Local time
Today, 09:48
Joined
Mar 9, 2014
Messages
5,473
Adjust expression from post 17 to use [mass required]:

[unit price] * IIf([currency] <> "UGX", [exchange], 1) * IIf([mass required], [mass], [qty])
 

Gismo

Registered User.
Local time
Today, 20:48
Joined
Jun 12, 2017
Messages
1,298
Although using Me is often very helpful in clarifying your code and bringing up intellisense, in truth it is rarely required in a form/report module.
Any property of a form is accessible without the Me keyword so you can simply write the control name or field name or other property.
Mass.enabled is the same as Me.Mass.enabled
Same principle as Application
I never seen anyone write
Application.Docmd
But that is the full qualifier

@Gismo,
Also I am guessing you also need to put the code in the after update of the MassRequired
Code:
Private Sub Form_Current()
EnableDisableMass
End Sub

Private Sub EnableDisableMass()
  Me.Mass.Enabled = Me.MassRequired
  Me.Mass.TabStop = Me.MassRequired
End Sub

Private Sub MassRequired_AfterUpdate()
EnableDisableMass
End Sub

Works perfectly fine for me.
Hi,

I used you sample as is, for some reason when mass is required the mass control is not active
When I switch to design view and back to form view, the mass control becomes active

Please could you advise?
 

Gismo

Registered User.
Local time
Today, 20:48
Joined
Jun 12, 2017
Messages
1,298
Now attached
Hi,

When I make a new form as per your sample, it works fine
When I amend my old form, the mass control is tabbed irrespective of the mass required or not
Only when I go to design view and back to form view that the code worked

After I have selected the product, below is the code

Private Sub Product_AfterUpdate()
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenQuery "Update Transaction - Procurement - Temp - Currency"
DoCmd.OpenQuery "Update Transaction - Procurement - Temp - UOM"
DoCmd.GoToControl "Qty"
Qty.Requery
DoCmd.SetWarnings True


Dim value As Currency
If Not IsDate(Me.[Transaction Date]) Then
MsgBox "Please enter a valid date!"
Exit Sub
End If

Call fncUpdateFields

End Sub

Please could you advise
 
Last edited:

Gismo

Registered User.
Local time
Today, 20:48
Joined
Jun 12, 2017
Messages
1,298
I managed to get this going

I added the code to the after update when I select the product

Private Sub EnableDisableMass()
Me.Mass.Enabled = Me.MassRequired
Me.Mass.TabStop = Me.MassRequired
End Sub
Private Sub Product_AfterUpdate()
DoCmd.SetWarnings False
EnableDisableMass
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenQuery "Update Transaction - Procurement - Temp - Currency"
DoCmd.OpenQuery "Update Transaction - Procurement - Temp - UOM"
Me.Mass.Enabled = Me.MassRequired
Me.Mass.TabStop = Me.MassRequired
EnableDisableMass
DoCmd.GoToControl "Qty"
Qty.Requery
DoCmd.SetWarnings True


Dim value As Currency
If Not IsDate(Me.[Transaction Date]) Then
MsgBox "Please enter a valid date!"
Exit Sub
End If

Call fncUpdateFields

End Sub
 

Users who are viewing this thread

Top Bottom