Question Transforming/Recoding Variable

ydntkmn

New member
Local time
Today, 21:51
Joined
Nov 2, 2017
Messages
2
I am a layperson trying to use Access to manage some data.

I have a variable which I would like Access to reverse for me. I would like to have one column "A" with the data I enter (1,2,3,4) and one column with the data reversed (if A=1, 4; if A=2, 3; etc) that Access calculates for me.

Is there a way I can do it?

Thank you!
 
you may need to create a function and call that function to update the second field. if you want just to show the reverse in a query, just call it without saving to table:


public function fnReverseContent(fieldValue as variant) as variant
dim varReturn as Variant
dim varArray As Variant

Dim i As Integer

'supposing that the field is separated by ","
varArray=Split(FieldValue & "", ",")
For i = UBound(varArray) To LBound(varArray) Step -1
varReturn = varReturn & varArray(i) & ", "
Next
If Len(varReturn)<>0 Then varReturn = Left(varReturn, Len(varReturn)-Len(", "))
ftReverseContent = varReturn
End Function




to update in SQL
DoCmd.RunSQl "Updat tabl1 set Field2 = ftReverseContent(field1);"




in query:


SELECT field1, ftReverseContent(field2) As Reverse From table1
 
Or if this is in a query and this encoded field has a known & guaranteed maximum and you are talking about simple reversal...

Code:
SELECT A, (n-A) AS ARev, ... FROM .... ;

where n is your maximum A value plus 1. So if the maximum of A is 4, you would use 5.
 
Or if this is in a query and this encoded field has a known & guaranteed maximum and you are talking about simple reversal...

Code:
SELECT A, (n-A) AS ARev, ... FROM .... ;

where n is your maximum A value plus 1. So if the maximum of A is 4, you would use 5.

thank you! I just did this and it was suitable for my novice amount of knowledge.
 

Users who are viewing this thread

Back
Top Bottom