Display only last two digits

Ali Edwards

Registered User.
Local time
Today, 11:28
Joined
Apr 19, 2001
Messages
68
Hi all.

Is there a way to make a text box display only the last two digits? eg '105' is displayed as '05', '115' as '15'.
I have tried the following in the format property for the text box which I read on the forum here but they don't work:

"Mid([Otdr Index2],2,2)"
or
"Right([Otdr Index2],2)"

Many thanks
 
Use an unbound textfield and set the controlsource to =Right([NameOfFullFieldControl],2)
This will be a display-only field and will change according to the value you place in your full value field control.
HTH
 
Thanks Fizzio.
This is clever stuff but unfortunately won't solve my problem as there are in fact 24 of these little text boxes and I really don't have the room on the form for another 24 unbound text boxes. (Nor do I want the confusion of all those!)

The heart of the problem really is that, although the user can type any value into any of the 24 "OTDR Index" fields, I wanted them to default to there most common value after the first one is input. ie. if "1" is typed into "OTDR index1" , "OTDR Index2" would = 02, the third = 03 etc.

Because I want a two digit view (ie displaying a leading zero for single numbers) I had to put this code on the After_Update of "OTDR Index1":

[OTDR Index2] = "0" & [OTDR Index1] + 1
[OTDR Index3] = "0" & [OTDR Index2] + 1
etc, etc
[OTDR Index24] = "0" & [OTDR Index23] + 1

This works fine until the first box ="10" or higher because the following boxes display "011", "012" etc instead of "11", "12" etc.

Perhaps there is a better way to automatically increment the values after "OTDR Index1", without using Autonumber and such that the user can overtype any default value assigned if neccessary.

Of course I could just narrow down the size of the field to "hide" the zero but I imagine the user would run into problems if they had to overtype a default value and I'm sure there must be a way to display just the last two digits.

If anyone has a solution I would be very grateful.

Thanks again.
Ali
 
If the values will never go above 99 then set the format of the control to 00 then 1 will become 01 etc and 10 will be 10, however 115 will still be 115. Do you want them to just display the last 2 digits or store the last 2 digits. The latter is east, the former I haven't worked out yet!
 
Hi Fizzio - glad to have you back!
I need to store the value in the underlying table (don't mind if this is three digits ie 006) and to display just two (ie 06).

I just tried setting the format to 00 and this still displays "011" instead of "11". I guess this is because my code: "[OTDR Index2] = "0" & [OTDR Index1] + 1" which is great for numbers 1-9 (producing 01-09) but falls out of bed when numbers 10+ are added.
If I make the code "[OTDR Index2] = [OTDR Index1] + 1" then I can't get numbers 1-9 to display "01 - 09", even with the format set to "00".

Weird that this should be so hard to do!!
Continued thanks!
 
A few Q's

Is there a possibility of having a value of >99?
If so if a value is 115 do you need to store 115 in the underlying table or just 15?
When you input Otdr Index1 will this ever need to be changed?
Do you need to access Otdr Index2 etc?

A couple of tips. Avoid including spaces in field/control/table names etc.
When setting the value of the other textboxes, calculate them all on Otdr Index1, not cascading (Increases speed)
 
Fizzio, Thanks for the tip about calculating all the fields on OTDR Index1. That makes good sense.

It is highly unlikely that a value would get as high as 99 or more, but if it were to happen then 115 would need to be displayed as 115. It is so unlikely that I feel it isn't necessary to cater for if it makes solving this problem easier.

After OTDR Index1 is input it would only need to be changed if the wrong value was typed in. It will sometimes be necessary to alter the following OTDR Index boxes. For example if OTDR Index1 = '01 and the following 23 boxes 'autofill' to '02' to '24', it might be necessary to input say '17' in OTDR Index9, so that OTDR Index10 to 24 'autofill' to '18'-'32'.

This is actually how it is working at the moment successfully. Only problem is I just want to display two digits! I think it is the rather 'mechanical' way in which I'm forcing values 1-9 to display as 01-09.

Maybe I could replace the code
[OTDR Index2] = "0" & [OTDR Index1] + 1
with
[OTDR Index2] = [OTDR Index1] + 1
then have some kind of code that adds a leading zero if the value is =<9??

Thank you for your continued efforts!

Ali
 
Ali, I see now why you are cascade calculating esp if you need to chance otdr9 and then 10 - to reflect this change. Keep your calculation the same. I had a play with this myself and on setting all the textbox formats to 00 when I inputted a value into txt1, txt2,3 etc showed 02,03 etc so I'm not sure what is going on there. My code was similar to yours, ie

me.txt2 = me.txt1 + 1
me.txt3 = me.txt2 + 1
etc, etc
me.txt23 = me.txt24 + 1

I have referenced the control via the 'me.' prefix. Have you tried referencing your controls this way?
 
Fizzio,

I've changed to the me. prefix and checked that the format is set to 00 and, alas, it just won't play! Maybe it's because I'm using Access97 and you're on 2000? Just wondering if this is a limitation with A97...
Anyway, thank you for all your help. It looks like I might just have to live with 1-9 being single numbers.
If ever I'm up your way I'll look you up for some physio on my kneck!
Ali
 
No probs - keep plugging away but I'll have a look at the Db if you want. I should open up a virtual clinic to help ease the physical stresses of working with Access.
 

Users who are viewing this thread

Back
Top Bottom