growing text box to show all data ?

smig

Registered User.
Local time
Today, 20:05
Joined
Nov 25, 2009
Messages
2,209
is there a way to make a text box grow when it get the focus, so I can see al the data in it ?
I want only the specific one to grow on a continous form.
tried to use the .OnGotFocus event to set the .CanGrow property but ended with an error

thanks,
Tal
 
In a report Yes on a form No.

Having said that you can turn on the vertical scroll bar for your text box.
 
Another approach would be to use the ZoomBox command. This will zoom the text box if it has data in it:
Code:
Private Sub YourControl_GotFocus()
  If Nz(Me.YourControl,"")<>"" Then
    DoCmd.RunCommand acCmdZoomBox
  End If
End Sub
If you want the text box to zoom for the initial data entry as well as later viewing use
Code:
Private Sub YourControl_GotFocus()
  DoCmd.RunCommand acCmdZoomBox
End Sub
Linq ;0)>
 
The zoom box is a good one for something like this.

One other way is to "fill" your form's Footer section with a textbox, lock it, set the textbox's value accordingly and set the back color accordingly based (i.e. white when there's text and grey when Null or zls, or switch the Locked and Enabled property values to create a similar effect).
 
thanks for the help
I thought of making my oun ZoomBox as I don't like the look of the original one.
using the footer is nice idea, though I think the footer is kinda out of focus.

Thanks
 
Let us know which approach you choose in the end.
 
...I don't like the look of the original one.
Actually, I don't like it either! Another fairly simple way would be to place a large text box (call it MyZoomBox) on your form. Format it as you like, position as you like and assign it the same Control Source as the field you want to expand. Yes, a form can have two textboxes with the same Control Source!

Substitute the actual name of your field to be expanded for YourTextBox.

Code:
Private Sub Form_Load()
'Make the zoombox invisible on loading the form    
 MyZoomBox.Visible = False
End Sub
Code:
Private Sub [B]YourTextBox[/B]_DblClick(Cancel As Integer)
'When you double click the field, make the MyZoomBox
'visible and move the cursor to the beginning to
'deselect the text  
  MyZoomBox.Visible = True
  MyZoomBox.SetFocus    
  MyZoomBox.SelStart = 0
End Sub
Code:
Private Sub MyZoomBox_DblClick(Cancel As Integer)
'Double click the MyZoomBox to close it and
'return to your original field
  Me.[B]YourTextBox[/B].SetFocus
  MyZoomBox.Visible = False
End Sub
Now make the zoombox visible by double clicking the field you want expanded. Do whatever you want to the data, then double click the zoombox to close it.
 
thanks for all the help
I decided to go with my oun ZoomBox. funny, I named it exactly as missinglinq suggested :D

as for now I only need it for uneditable forms (data can't be changed).
as I use doubleClick all over my application it won't be used for this. I decided to go with a Button click. I think the space will be the best, mostly because it's the most reachable key (both by size and location) it will be also be used to close the box. but this mightbe changed to the WinKey or Shift+Space, as I might want it for editable places at later time.

I also want it to be much more global, an to work for all forms.
so I'm using a global code for this:
Code:
Public Sub SetZoomBox(frm As Form)
On Error GoTo errHere
 
Dim ctl As Control
Dim strCntrl As String
For Each ctl In frm.Controls
    With ctl
        If .ControlType = acTextBox Then
            .OnKeyDown = "=OpenZoomBox([" & .name & "].[Parent] ,'" & .name & "' ," & KeyCode & ")"
        End If
    End With
Next ctl
 
exitHere:
    Exit Sub
errHere:
    Call ErrorHandling("mdl_SetZoomBox", "SetZoomBox", Err, Err.Description)
    Resume exitHere
End Sub
 
Public Function OpenZoomBox(frm As Form, strCntrl As String, KeyCode As Integer)
 
On Error GoTo errHere
 
MsgBox KeyCode
'If KeyCode = 32 Then
    DoCmd.OpenForm "MyZoomBox_Form", acNormal, , , , acDialog, frm.Controls(strCntrl).Value & "|" & frm.Controls("ZoomColor").BackColor
'End If
 
exitHere:
    Exit Function
errHere:
    Call ErrorHandling("mdl_SetZoomBox", "OpenZoomBox", Err, Err.Description)
    Resume exitHere
End Function

in my OnOpen event of the form I need a zooming for I call the
SetZoomBox(me)

this code will enable zooming for all text boxes on form.
as you can see I send the ZoomBox the Value of the text box and a color so I can color the ZoomBox with the same color I use for the form, to make it nicer :)

My only problem now is I can't find the correct way to send the KeyCode data.
the current code simply send 0
I tried these, but they gave me an error:
.OnKeyDown = "=OpenZoomBox([" & .name & "].[Parent] ,' " & .name & " ' ,' " & KeyCode & " ')"

.OnKeyDown = "=OpenZoomBox([" & .name & "].[Parent] ,' " & .name & " ' , KeyCode)"
 
A double click event is the most intuitive for performing this kind of function. What do you currently have in there?

How many textboxes are you applying this onto?

Sub parameters (such as KeyCode) are not available in the Expression Builder. You must do it directly in each Sub.
 
I know DblClick is very intuitive but I'm using it to go into edit mode, and this is not going to be changed now. not after this application is in use for 3 or 4 years.

are you saying there is no way to get the KeyCode ?
 
Maybe give them options when they double click - edit or zoom. Or one of the Function keys or Ctrl + Z.

Yep, that's right! Well, not with the way you're currently doing it. You have to use Code builder and Call the function inside each Key Down sub routine.
 
ha I found a way
if you set the form's KeyPreview to true it will recieve the key before the control.
now I can use the Form's KeyDown event to save the key presset into a public variable :)

Guess I'll use Shift+Space
I loved to use also Shift+Alt, Shift+CTrl, but these are used to change language.
I can use Space for non editable forms, and Shift+Space for editable ones, but I think it's better to keep it all the same
 
smig

just one other thought

you can actually place a button over the control, and click the button. you can make the button TRANSPARENT, so it looks like you are clicking the control - but you aren't - you are clicking a button. Useful if the field itself is not enabled.
 
Isn't it the same as using the OnGotFocus or OnClick events of the control itself?
I thought about it and I don't want it to pup all the time, only when the user want to pop it up.

It was missinglinq's doing :)
Don't underestimate your help here, not to mention your help in all other places :)
saying it's not possible sending the KeyCode using the Expression Builder made me to look for another solution :)
 

Users who are viewing this thread

Back
Top Bottom