Solved How to right align a series of texts? (1 Viewer)

Sun_Force

Active member
Local time
Tomorrow, 02:53
Joined
Aug 29, 2020
Messages
396
I need some advice on how to right align a series of text.
I tried the following :
SQL:
    St = "WWW"
  
    C = "3"
    RSet St = C
    Debug.Print St & "P"
  
    C = "33"
    RSet St = C
    Debug.Print St & "P"
  
    C = "333"
    RSet St = C
    Debug.Print St & "P"

but the result is not what I expect. Apparently it's not right aligned.

2021-08-31_8-42-50.jpg


If I use it as a function :
SQL:
Function test2(C As String)
    Dim St As String
    St = "WWWW"
    RSet St = C & " P"
    test2 = St
End Function

I receive this. Again not right aligned.

2021-08-31_8-46-54.jpg


This is the query's sql :
SELECT test2([ShowOrder]) AS Expr1 FROM tblProcesses;

Any kind of advice is much appreciated.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:53
Joined
Oct 29, 2018
Messages
21,474
Hi. To properly line up different length of text, you'll have to use a mono space font like Courier.
 

Sun_Force

Active member
Local time
Tomorrow, 02:53
Joined
Aug 29, 2020
Messages
396
Hi. To properly line up different length of text, you'll have to use a mono space font like Courier.

I'm aware of that. While I'm trying to follow your advice, but I'm using the same character over and over (3)
Since the width for this character (3) is always the same, even in a non mono space font, does it make any difference which font to use?

thanks

Edit : Seems that you're correct (as ever). Changing the font to Courier gives the correct result.
 

MarkK

bit cruncher
Local time
Today, 10:53
Joined
Mar 17, 2004
Messages
8,181
I would bind the query to a form, and set the alignment of the control that's bound to that field.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:53
Joined
May 7, 2009
Messages
19,245
do you want to Align it on the Query.
You don't need function Test2() to align it.
all you need is Format the Column As numeric.
in design view of your query, add # as Format of that column.
with or without Form, it will align properly.
 

Sun_Force

Active member
Local time
Tomorrow, 02:53
Joined
Aug 29, 2020
Messages
396
do you want to Align it on the Query.
You don't need function Test2() to align it.
all you need is Format the Column As numeric.
in design view of your query, add # as Format of that column.
with or without Form, it will align properly.
@arnelgp
What I wanted to show, is a text. not a number.
It was just a test to learn about Rset.
A while back you posted a file to show how to right align and left align a text. I downloaded your file, but I was in the middle of the college tests and wasn't able to go through your file.
This morning I was free and took a look at your file. I tried to test Rset and I wasn't able to make it work.
In case you have forgotten what you posted, this is the file I'm talking about.
 

Attachments

  • paddedString.accdb
    512 KB · Views: 101

theDBguy

I’m here to help
Staff member
Local time
Today, 10:53
Joined
Oct 29, 2018
Messages
21,474
I'm aware of that. While I'm trying to follow your advice, but I'm using the same character over and over (3)
Since the width for this character (3) is always the same, even in a non mono space font, does it make any difference which font to use?

thanks

Edit : Seems that you're correct (as ever). Changing the font to Courier gives the correct result.
Hi. Glad to hear you got it sorted out. Cheers!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:53
Joined
May 7, 2009
Messages
19,245
yes it is a text, Format applies only to the "appearance" in query
and does not alter anything.
see Query2, you can also edit record/add records.
there is no need to change "font" also.
 

Attachments

  • paddedString.accdb
    512 KB · Views: 113

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:53
Joined
Feb 19, 2002
Messages
43,275
I hate to repeat earlier advice but there is no reason to align text in a query. Users should only be viewing reports and forms, NOT raw queries. Both Forms and Reports allow you to Right align text fields with a property setting. AND unless you are using a non-proportional font, the code alignment probably won't actually work anyway because each character takes a different amount of space.
 

Sun_Force

Active member
Local time
Tomorrow, 02:53
Joined
Aug 29, 2020
Messages
396
I hate to repeat earlier advice but there is no reason to align text in a query. Users should only be viewing reports and forms, NOT raw queries. Both Forms and Reports allow you to Right align text fields with a property setting.

1-Thanks for your advice. But as I explained earlier, I had never seen Lset or Rset and I was just testing to see how it works.
2- If you check @arnelgp's sample file, even forms and reports don't allow you to right align and left align a text at the same time in the same textbox. His sample file was in response to a member who needed to do so and his solution was brilliant to me.

AND unless you are using a non-proportional font, the code alignment probably won't actually work anyway because each character takes a different amount of space.
I still don't understand why the code in my first post doesn't work. If I had tried to output different text/letters, you are right because apparently the width of "l" is different with the width of "W". But I had used the number "3" over and over, still Rset didn't right aligned the text. It was rather center aligned. 33's width is twice 3 and 333 is triple. So how comes the out put is not aligned?
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 18:53
Joined
Feb 19, 2013
Messages
16,614
Because it is packed out with spaces - and they are not the same width as a 3 - except for fixed width fonts. The ‘333’, ‘www’ whatever is merely a character count.

read this link about rSet
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:53
Joined
Feb 19, 2002
Messages
43,275
Queries and tables in DS view are NOT intended for user viewing but, Access does have a setting that lets you change the font and size for display purpose. I don't know whether this is a "your" computer or "all users" setting so it may not port to any user computers.
 

Users who are viewing this thread

Top Bottom