Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    brc is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    29

    Right Align Listbox

    Is there a way to right align a listbox?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Google: access right align listbox
    Check this http://sites.google.com/site/msacces...entforalistbox

    I opened the project from that site in 2010 and the listboxes align only left, didn't test in 2007 yet.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    brc is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    29
    Ya I tried that technique which seemed to work until I run the report and the listboxes go back to left aligned. Seems kind of weird that a person can only left align in a listbox.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    The only other thing I can think of is to pad the values with leading spaces or zeros. I do that with a custom function.
    Code:
    Private Function Pad(varText As Variant, strAlign As String, intLength As Integer) As String
    If Len(varText) >= intLength Then
    'if the source string is longer than the specified length, return the Length left characters
    Pad = Left(varText, intLength)
    ElseIf strAlign = "L" Then
    'text aligns left, fill out the right with spaces
    Pad = varText & String(intLength - Len(varText), " ")
    Else
    'text aligns right, fill out the left with spaces
    Pad = String(intLength - Len(varText), " ") & varText
    End If
    End Function
    I took another look at that sample db in 2007 and it shows the same as in 2010. In design view the listboxes show the center and right alignment but in form view all is left aligned. The video from the site clearly demonstrates the technique. The author's demo was for form not report. Simply does not work for me.
    Last edited by June7; 07-10-2011 at 03:42 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    brc is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    29
    Ya I tried Leban's Justicombo also but it's not working using a report. anybody know of a way to make that work for a report. Works fine on a form.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    I just tested Lebans code. In his demo project I built a report based on the demo form frmJustify and copied the listboxes over to the report. It works great. Did not test the code in a new project.

    His code is also padding with space characters, just more sophisticated.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by brc View Post
    Ya I tried Leban's Justicombo also but it's not working using a report. anybody know of a way to make that work for a report. Works fine on a form.
    Combos are not really good for reports as there is no real need for them as you can't select anything from them and they can only show one field while on there. Why not just use a text box instead?

  8. #8
    brc is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    29
    @June7, i did that also but when you ran the report was the form still open? I tried it and it worked but as soon as I closed the form it didn't work in report.

    @bobLarson. Can a textbox display a column of data like a listbox?

  9. #9
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by brc View Post
    @bobLarson. Can a textbox display a column of data like a listbox?
    You can use text boxes formatted to look like it is a listbox. And by using separate ones you can have it justify each field the way you want it justified. All it takes is a little bit of work and formatting.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Bob, Lebans calls it Justicombo but it is for list boxes.

    brc, yes the form was open and closed the values don't show. I will have to play with this some more this weekend. Using VBA can build one long string with concatenation to appear as columns and multiple rows (using vbCrLf in VBA and Chr(13) & Chr(10) in Access) but will still need a padding function. I do this for several reports.
    Last edited by June7; 07-09-2011 at 12:58 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    brc is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    29
    bob, so in your opinion what is better to do? a whole bunch of textboxes or space padded listbox?

  12. #12
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by brc View Post
    bob, so in your opinion what is better to do? a whole bunch of textboxes or space padded listbox?
    It depends on what will actually work for your purposes and cause you the least amount of suffering when trying to get it to work I guess.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    I don't know how Lebans code would have to be modified to work for a report without the form open but I tested my little function and it did the job. I changed it to a Public function, put it in a general module and then called it in the listbox RowSource SQL.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    brc is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    29
    Ok Thanks June7 I will give that try

  15. #15
    brc is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    29
    OK, June7 I have got your code to work but the original control was set to currency format which this code seems to strip. Is there a way to keep datatype as currency or do i have to add .00 and $ to each number if needed?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Listbox Help
    By allykid in forum Programming
    Replies: 2
    Last Post: 03-30-2011, 06:17 AM
  2. How to vertically align text inside a text box ?
    By alexcalgary in forum Forms
    Replies: 2
    Last Post: 10-06-2010, 08:44 AM
  3. Horizontal listbox - ?
    By bane in forum Forms
    Replies: 3
    Last Post: 04-20-2010, 06:48 PM
  4. Align Fields
    By saqqer in forum Programming
    Replies: 1
    Last Post: 08-04-2009, 07:30 PM
  5. Replies: 2
    Last Post: 12-19-2005, 09:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums