right align in vb code?

B

_Bigred

Im using the following code:


ct = Format((rst![Inmate#]) & " " & (rst![Restrictions]) &
vbNewLine & vbNewLine & (rst!LastName) & ", " & (rst!FirstName) & (rst!
CellDate))


This would be in a unbound textbox on a report and would display the
data the following way:

123456 LowBunk
(empty line here using vbNewLine)
Doe, John02242009

I would want the date (rst!CellDate) to go the farthest right that it
can go, but I can't set it by using the &" " because the name(s)
are varied in length.

How can I set the (rst!CellDate) to display in a right align format?

TIA,
_Bigred
 
P

Piet Linden

Im using the following code:

ct = Format((rst![Inmate#]) & "             " & (rst![Restrictions]) &
vbNewLine & vbNewLine & (rst!LastName) & ", " & (rst!FirstName) & (rst!
CellDate))

This would be in a unbound textbox on a report and would display the
data the following way:

123456            LowBunk
(empty line here using vbNewLine)
Doe, John02242009

I would want the date  (rst!CellDate) to go the farthest right that it
can go, but I can't set it by using the &"     " because the  name(s)
are varied in length.

How can I set the (rst!CellDate) to display in a right align format?

TIA,
_Bigred

You would probably have to use SPACE(number) and then do some math
with len() then you can force everything to be formatted properly...
 
S

Stuart McCall

_Bigred said:
Im using the following code:


ct = Format((rst![Inmate#]) & " " & (rst![Restrictions]) &
vbNewLine & vbNewLine & (rst!LastName) & ", " & (rst!FirstName) & (rst!
CellDate))


This would be in a unbound textbox on a report and would display the
data the following way:

123456 LowBunk
(empty line here using vbNewLine)
Doe, John02242009

I would want the date (rst!CellDate) to go the farthest right that it
can go, but I can't set it by using the &" " because the name(s)
are varied in length.

How can I set the (rst!CellDate) to display in a right align format?

TIA,
_Bigred

Do yourself a favour and have the data displayed in separate textboxes
instead of cramming it all into one. Create and position the following
textboxes:

txtInmate
txtRestrictions
txtLastName
txtFirstName
txtCellDate

Set the 'Text Align' property of txtCellDate to 'Right'.

Now change your code to:

txtInmate = rst![Inmate#]
txtRestrictions = rst![Restrictions]
txtLastName = rst!LastName
txtFirstName = rst!txtFirstName
txtCellDate = rst!CellDate
 
S

Stuart McCall

Oops. Correction:

This line:

txtFirstName = rst!txtFirstName

ought to read:

txtFirstName = rst!FirstName
 
D

DaveT

One general method would be:

Dim strText As String * 40 'fixed length string
Dim strLeftStuff As String
Dim strRightStuff As String

strLeftStuff = "12345"
strRightStuff = "LowBunk"

RSet strText = strRightStuff 'right set the right hand stuff
Mid(strText, 1) = strLeftStuff 'plug the left hand stuff into the string
starting a pos 1

'Debug.Print strText
'12345 LowBunk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top