On Click Code Nor Working (1 Viewer)

access2010

Registered User.
Local time
Today, 13:45
Joined
Dec 26, 2009
Messages
1,021
We enter data into the field -> PE_Ratio

On the click [Event Procedure]
I would like to copy the data in the field PE_Ratio to => PE_Ratio_Previous and copy the data in PE_Ratio_Previous to => PE_Ratio_Earliest

Could I receive a suggestion as to what I am doing wrong, as our results do not work, in either of the below codes in our Access 2003 database?

Me.PE_Ratio = Me.PE_Ratio_Previous
Me.PE_Ratio_Previous = Me.PE_Ratio_Earliest

' === PE Ratios
Me.PE_Ratio_Previous = Me.PE_Ratio
Me.PE_Ratio_Earliest = Me.PE_Ratio_Previous

Thank you.
Nicole
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:45
Joined
Oct 29, 2018
Messages
21,474
If you want to move the values around, you can either store them in variables first, so you don't lose their values, or work in correct order by replacing the oldest (earliest) value first and work your way to the current one. For example, if by updating A you want the value of A to go to B and the value from B to go to C, then do it in this order:
C = B
B = A
A = New Value
Hope that makes sense...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:45
Joined
Feb 19, 2002
Messages
43,281
If the control is updatable, you would NOT use the click event to perform this shifting process. You need to be able to click into the control in order to type data in it. To do the shift "right", use the double click event of the first or last control in the series or use a button. I like the button since it makes the interface clearer.
 

access2010

Registered User.
Local time
Today, 13:45
Joined
Dec 26, 2009
Messages
1,021
If you want to move the values around, you can either store them in variables first, so you don't lose their values, or work in correct order by replacing the oldest (earliest) value first and work your way to the current one. For example, if by updating A you want the value of A to go to B and the value from B to go to C, then do it in this order:
C = B
B = A
A = New Value
Hope that makes sense...
Thank you theDBguy for your suggestion. and below is what I think you have suggested, but the results are not what we are looking for


' A = Data Entered into => PE_Ratio
' B = Copy data from A to => PE_Ratio_Previous
Me.PE_Ratio = Me.PE_Ratio_Previous
' C = Copy data from B to => PE_Ratio_Earliest
Me.PE_Ratio_Previous = Me.PE_Ratio_Earliest

Crystal
 

access2010

Registered User.
Local time
Today, 13:45
Joined
Dec 26, 2009
Messages
1,021
If the control is updatable, you would NOT use the click event to perform this shifting process. You need to be able to click into the control in order to type data in it. To do the shift "right", use the double click event of the first or last control in the series or use a button. I like the button since it makes the interface clearer.
Thank you Pat Hartman for a new word, "Shifting"

We are moving and copying many items on our form with the Click Event, but are only stuck with this part.

Crystal
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:45
Joined
May 7, 2009
Messages
19,245
We enter data into the field -> PE_Ratio
instead of Click Event, you can also do it it the BeforeUpdate Event of field PE_Ratio.

Code:
Dim var As Variant

Private Sub PE_Ratio_BeforeUpdate(Cancel As Integer)
    var = Me!PE_Ratio.OldValue
    Me!PE_Ratio_Earliest = Me!PE_Ratio_Previous
    Me!PE_Ratio_Previous = var
End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:45
Joined
Feb 19, 2002
Messages
43,281
We are moving and copying many items on our form with the Click Event, but are only stuck with this part.
The click event of a textbox is NOT the correct event to use for this type of process. EVERY form/control event has a purpose. It is important to understand what the events are intended to be used for - the events are NOT random - so you put your code in an event that makes sense.

@arnelgp suggested the PE_Ratio control's BeforeUpdate event, I wouldn't use that event, I would prefer a more targeted action which is why I suggested a button. Using a button, also gives you the ability to "undo" the shift by clicking a second time.

However, the control's BeforeUpdate event makes much more sense in the greater scheme of things than the Click event does. At least you know the user had some intention to make something happen because he modified a value. With the click event, the user could just have accidentally clicked into the field and had no intention to change anything. You always have to keep user expectations and YEARS worth of typing on a computer in mind. No one "expects the Spanish Inquisition" or the click event to initiate an update action and that makes it dangerous for this purpose.

** That was a Monty Python reference for those who have never run into this group of very funny Brits.
 

access2010

Registered User.
Local time
Today, 13:45
Joined
Dec 26, 2009
Messages
1,021
Tha
instead of Click Event, you can also do it it the BeforeUpdate Event of field PE_Ratio.

Code:
Dim var As Variant

Private Sub PE_Ratio_BeforeUpdate(Cancel As Integer)
    var = Me!PE_Ratio.OldValue
    Me!PE_Ratio_Earliest = Me!PE_Ratio_Previous
    Me!PE_Ratio_Previous = var
End Sub
Thank you arnelgp for your suggestion which we have tried without success.

Could you please offer us your comments by looking at the attached Access 2003 form which we are trying to use your suggestion in.

Thank you.
Nicole
 

Attachments

  • PE_23_033.mdb
    352 KB · Views: 56

access2010

Registered User.
Local time
Today, 13:45
Joined
Dec 26, 2009
Messages
1,021
The click event of a textbox is NOT the correct event to use for this type of process. EVERY form/control event has a purpose. It is important to understand what the events are intended to be used for - the events are NOT random - so you put your code in an event that makes sense.

@arnelgp suggested the PE_Ratio control's BeforeUpdate event, I wouldn't use that event, I would prefer a more targeted action which is why I suggested a button. Using a button, also gives you the ability to "undo" the shift by clicking a second time.

However, the control's BeforeUpdate event makes much more sense in the greater scheme of things than the Click event does. At least you know the user had some intention to make something happen because he modified a value. With the click event, the user could just have accidentally clicked into the field and had no intention to change anything. You always have to keep user expectations and YEARS worth of typing on a computer in mind. No one "expects the Spanish Inquisition" or the click event to initiate an update action and that makes it dangerous for this purpose.

** That was a Monty Python reference for those who have never run into this group of very funny Brits.
Thank you Pat for your suggestion which we have tried without success.

Could you please offer us your comments by looking at the attached Access 2003 form which we are trying to use your suggestion in.

Thank you.
Nicole
 

Attachments

  • PE_23_033.mdb
    352 KB · Views: 48

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:45
Joined
May 7, 2009
Messages
19,245
check and test.
note that i comment Out below lines since
you don't have "qry_UpdateAdvice query on your uploaded db.

If Not IsNull(Me.Symbol_Stock) Then
...
...
 

Attachments

  • PE_23_033.mdb
    1.1 MB · Views: 62

access2010

Registered User.
Local time
Today, 13:45
Joined
Dec 26, 2009
Messages
1,021
check and test.
note that i comment Out below lines since
you don't have "qry_UpdateAdvice query on your uploaded db.

If Not IsNull(Me.Symbol_Stock) Then
...
...
Thank you arnelgp for your suggestion, but we are still not obtaining the results we would like.

Attached is a more complete database that may help you find out what our problem is.

===
One of the NGOs that I volenteer at is trying to create a General Ledger, could you please point us to some ideas that we could use for them or suggest where we could find an Access 2003 General Ledger.

We always appreciate your assistance.

Crystal
 

Attachments

  • PE_23_033_Second.mdb
    972 KB · Views: 132

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:45
Joined
Feb 19, 2002
Messages
43,281
I think Database Creations is no longer operating but I found this link:
If it is the software, you might be able to decompile it or maybe you'll get lucky and be able to find Cary. I think the company was in Windsor, Connecticut or somewhere in that area north of Hartford.

There's a number of ways to do this. I added a button. I saved the old values so I could display them to make it easy to see that the shift works.

Another way instead of the button click is to use the AfterUpdate event of the PE_Ratio field. That way if you want to type in the new value first and then do the shift, then there is a slight change to the code. Since you are overwriting the original value, you obviously can't move the current value of the control to the previous slot,so you would use the .OldValue property. This maybe what you were missing in your other tries.

Either you shift BEFORE you change the PE_Ratio or you shift after, but when you shift after, you have to use a different property of the control. The code would then be:

If you use the AfterUpdate event of Me.PE_Ratio, then the code is this:
SaveValues = Me.PE_Ratio & "--" & Me.PE_Ratio_Previous & "--" & Me.PE_Ratio_Earliest
Me.PE_Ratio_Earliest = Me.PE_Ratio_Previous
Me.PE_Ratio_Previous = Me.PE_Ratio. oldValue ---- Apparently the combination of o dot o produces an emoji so I separated the . from the property name which is oldValue. Here it is a different way. Remove the two XX's. They are only to keep the emoji from forming.
Me.PE_Ratio_Previous = Me.PE_RatioXX.OldValue
MsgBox "for testing - old values = " & SaveValues

Once you see it working, just comment out the messagebox.
 

Attachments

  • PE_23_033_Second_Pat.mdb
    1.1 MB · Views: 60

access2010

Registered User.
Local time
Today, 13:45
Joined
Dec 26, 2009
Messages
1,021
Thank you all for your suggestions.

We now have our issue resolved

Crystal
 

Users who are viewing this thread

Top Bottom