Full Version: Displaying Text
UtterAccess Forums > Microsoft® Access > Access Forms
AlexaanderDK
What's the best way to show text on Form ? Text you don't want to edit but may need to scroll?

Must you use a control ?

I found a label has a size limit. Error 2176 'The setting for this property is too long." and no abiltiy to scroll.
A text box won't scroll properly and for some reason is showing the text as all selected.

Is there anything better ?

Thanks.
azolder
You can used a locked text box. Just a text box, with the Locked property (on the data tab) set to true. You can enter the field, even scroll if needed, but with the control locked you can't change the value.
BitBangerUSA
perhaps a control for a Memo field.

if you don't want the form to default to a particular control (and thus show all the contents selected, then set some other control to have the focus.

edit: or better yet, what azolder said.
tina t
QUOTE
A text box won't scroll properly and for some reason is showing the text as all selected.

hello Alex, not sure what you mean by "won't scroll properly". a textbox control has a Scrollbar property that allows you to set Vertical scrollbars if you wish. also, selecting all text automatically when you tab into a textbox control, is the default setting in A2003. you can change that, from the database window, via Tools | Options | Keyboard | Behavior entering field. note that the setting is changed for the entire database, not just a particular form or control. it may be changed for any db you open in Access on that computer, but i don't really know because i've never changed it. in most cases, the default "Select entire field" is the desired action because it makes data entry easier.

in some cases, of course, that's not true. in those cases, you can control where the cursor "lands" using VBA. when you have a specific textbox control that you want the user to be able to Tab into without automatically selecting the entire value in the control, you can use the SelStart and SelLength properties to control the entry point. for instance, the following code in a control's Enter event procedure, will put the cursor at the beginning of the text value, as

Me!MyControlname.SelStart = 0

to put the cursor at the end of the text in the control, use

Me!MyControlname.SelStart = Me!MyControlname.SelLength

for your situation, suggest you try setting the textbox control's Locked property to Yes, to prevent accidental/intentional edits. set the Scrollbar property to Vertical, and put the cursor at the beginning of the text, using the first line of code above, in the control's Enter event. see if that gets results that will work for you.

hth
tina
AlexaanderDK
I don't have locked set , but must have done something as I can't edit it (which is fine as that what's wanted)

Thanks for tip about selected tina, that worked just fine. If you could also remove the cursor altogether
that's be great! The text is there to read, cursor is just annoying (but pretty sure it can't be got rid off).

By scroll nicely I meant be like everything else - text moves with you as you drag the slider down. Instead of when you let go
(or click on the arrows).

Can you have a memo control ? Or is that a text box with certain properties set ?

Guess I have a different idea of what a text box should do, and keep looking for things like a left margin to indent it a bit.
And be nice for the mouse wheel to work...

But if this really is all you can have, will make do.
Thanks for the replies smile.gif
AlexaanderDK
I've moved the textbox left a little and made it and the Form the same backcolor.

Can I have match the Text box and Form size, so they can be dragged together larger/smaller ?
Is this a problem if the vertical scrollbar is showing.
cheekybuddha
>> Can I have match the Text box and Form size, so they can be dragged together larger/smaller ? <<

In A2k3 you can only do this with code, but, yes, it is very possible.

Are there any other controls involved on the form? Can we have a screenshot?

>> Is this a problem if the vertical scrollbar is showing. <<
Is this the form's scrollbar or the textbox's scrollbar?

It shouldn't be a problem, but you never know!

hth,

d
tina t
QUOTE
Can you have a memo control ? Or is that a text box with certain properties set ?

AFAIK, there is no native "memo" control in A2003.

QUOTE
Guess I have a different idea of what a text box should do, and keep looking for things like a left margin to indent it a bit.
And be nice for the mouse wheel to work...

well, yes, it'd be nice if Access had a few of the options we are used to having available in Word, but it is what it is. you might check out Lebans' website, Alex. i know he has a rich-text control, and i believe it's suitable for A2003, though i've never used it. it's possible it has some additional options besides extra formatting. and just poke around, there may be something else available that will help you out; Stephen Lebans did some amazing things with Access.

re your last post about resizing textbox and form simultaneously via dragging borders - hmm, i don't know. again, suggest Lebans website first, and UA's code archives - then just try googling to see what other clever folks may have come up with. if you find anything suitable, maybe you could post back with a link, so we all know where to find the goodies! :)

hth
tina
cheekybuddha
Tina,

>> re your last post about resizing textbox and form simultaneously via dragging borders - hmm <<

See my post #7

d
tina t
thanks, David, i didn't ignore your post. i was typing my post when yours hit, so i didn't see it beforehand. tina
cheekybuddha
Here's some code to demonstrate the basic concept:
CODE
Option Compare Database
Option Explicit

Private Sub Form_Resize()

  Call fResize
  
End Sub

Private Function fResize() As Boolean

  Dim lHeight As Long, lWidth As Long, _
      lDetailHeight As Long, lFormWidth As Long, _
      lRightOffset As Long, lBottomOffset As Long
  With Me
    lDetailHeight = .InsideHeight   ' - (.Section(acHeader).Height + .Section(acFooter))  '  if your form has header/footer
    lFormWidth = .InsideWidth
    lRightOffset = .txt1.Left       ' just for example - make evenly spaced
    lBottomOffset = .txt1.Top       ' just for example - make evenly spaced
    lHeight = lDetailHeight - (.txt1.Top + lBottomOffset)
    lWidth = lFormWidth - (.txt1.Left + lRightOffset)
    If .txt1.Width <> lWidth Then   ' don't change if not necessary - reduces flicker
      If lWidth >= 0 Then           ' belt and braces to avoid setting invalid value
        .txt1.Width = lWidth
      End If
    End If
    If .txt1.Height <> lHeight Then
      If lHeight >= 0 Then
        .txt1.Height = lHeight
      End If
    End If
  End With
  fResize = (err = 0)
    
End Function

This just assumes a single textbox on a form called 'txt1' and it's in the 'Detail' section of the form. It should be evenly spaced from each edge of the form.

It gets more tricky when there are other controls that may have to be kept in place, or original size!

hth,

d
AlexaanderDK
Many thanks David, just about to paste that in. Yes, it is a single text box on the Form.
AlexaanderDK
Yes, I think this is working but my Form isn't designed quite right.

I'll try and upload an image, the scroll bar is in the wrong place (should be on the right side, not half an inch in to the left).
But I don't know if if should be part of the Form or the Text box property, mines on the Text box and works badly. Maybe (really hopes!) a Form scrollbar works better ?

As the Form is resized, is the intent the scrollar come/go as when needed ?
(Yes I mean to remove the Restore button)
cheekybuddha
In the code, find the line:
CODE
' ...
    lRightOffset = .txt1.Left       ' just for example - make evenly spaced
' ...

Change it to:
CODE
' ...
    lRightOffset = 0
' ...

and see if that helps.

d
AlexaanderDK
it certainly did.. now where it should be!
So the scrollbar must be on the right control (the text box).

Thanks very much fo that bit of code, it's beaut.

I can see the other glitch now.. and I'm sure there's no fix - but you cannot
set scroll height, can you ? So there's not lines of white space after the text finishes.

How do you find it, Tina ?
tina t
very nice! it's code like David's that separates the men from the boys (or girls, but i didn't mean this to be a sexist thing) in Access. the thing about the white space after the end of the text - no, i don't think there's anything you can do about that. but you could look at it as a positive: you can be sure there's nothing else at the "bottom" of the textbox that you're overlooking... ;)

hth
tina
AlexaanderDK
Right Tina, a positive it is! And YES, Davids code made the text box so much better ! smile.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.