Log in

View Full Version : [SOLVED:] expansion (bound) textfield in continous subform



TonC
09-27-2024, 04:39 AM
Hello,

I have a form, and in that form is a continues subform.

One field in that subform is a bound textbox. I would like that if this box has the focus, the box expand till 10 cm (twixel?) Standard is the widht of this field 3 cm. (twixel?)

Offcourse when I open the mainform the textbox in the subform is widht 3 cm. I searched the internet over how to do the expand of this box, but I cannot find a solution to do the expansion.


Any help will be valued,

Regards, Ton from Holland :help

June7
09-27-2024, 07:50 AM
Exactly what have you tried and what happens? Setting Width property works for me.

This would require also moving any controls sitting at right of textbox.

Consider using ZoomBox feature. https://support.microsoft.com/en-us/office/use-the-zoom-box-to-enter-text-and-expressions-9a62d165-67f8-4790-bad8-a2c2e83dcedf

Gasman
09-27-2024, 12:13 PM
I did something similar for a combo


Private Sub cboFoodIDFK_GotFocus()
'Debug.Print Me.cboFoodIDFK.ColumnWidths
TempVars("FoodWidth").Value = Me.cboFoodIDFK.Width
'Debug.Print "GotFocus " & TempVars("FoodWidth").Value
Me.cboFoodIDFK.Width = "8000"
Me.cboFoodIDFK.ColumnWidths = ExpandCombo(Me.cboFoodIDFK.ColumnWidths)
End Sub


Private Sub cboFoodIDFK_LostFocus()
'Debug.Print "LostFocus " & TempVars("FoodWidth").Value
Me.cboFoodIDFK.Width = TempVars("FoodWidth").Value
Me.cboFoodIDFK.ColumnWidths = ShrinkCombo(Me.cboFoodIDFK.ColumnWidths)
End Sub



Public Function ExpandCombo(pstrWidths As String) As String
Dim strWidth() As String, strNewWidth As String
Dim i As Integer


strWidth() = Split(pstrWidths, ";")
'For i = 0 To UBound(strWidth)
' Debug.Print strWidth(i)
'Next
strWidth(1) = CStr(Val(strWidth(1)) * 1.5)


For i = 0 To UBound(strWidth)
strNewWidth = strNewWidth & strWidth(i) & ";"
'Debug.Print strWidth(i)
Next
'Debug.Print strNewWidth
ExpandCombo = Left(strNewWidth, Len(strNewWidth) - 1)
'Debug.Print "Expanding " & ExpandCombo
'MsgBox ExpandCombo
End Function


Public Function ShrinkCombo(pstrWidths As String) As String
Dim strWidth() As String, strNewWidth As String
Dim i As Integer


strWidth() = Split(pstrWidths, ";")
'For i = 0 To UBound(strWidth)
' Debug.Print strWidth(i)
'Next
strWidth(1) = CStr(Val(strWidth(1)) / 1.5)


For i = 0 To UBound(strWidth)
strNewWidth = strNewWidth & strWidth(i) & ";"
'Debug.Print strWidth(i)
Next
ShrinkCombo = Left(strNewWidth, Len(strNewWidth) - 1)
'Debug.Print "Shrinking " & ShrinkCombo
'MsgBox ShrinkCombo
End Function

TonC
09-28-2024, 03:25 AM
Hello June7,

I was familiar with the option ZOOM, when I use the option, the popup box can I change the borderline?
Is there no other way to do this with VBA?
Like:

Private Sub Omschrijving_GotFocus()
Me.Omschrijving.Width = 6500
Me.Omschrijving.SetFocus
Me.Omschrijving.SelLength = 0
Me.Omschrijving.SelStart = Nz(Len(Me![Omschrijving]), 0) + 1
End sub

And:

Private Sub Omschrijving_LostFocus()
Me.Omschrijving.Width = 1440
End sub

This code was written in the subform, didd not work.

When you look,
https://www.youtube.com/watch?v=NMWksevolhc
you know what I mean.

By the way, I use access 2016

June7
09-28-2024, 12:35 PM
"did not work" means what - error message, wrong result, nothing happens?

Works for me in subform.

I've never utilized ZoomBox. What is borderline?

arnelgp
09-29-2024, 01:29 AM
add a "special" key (shortcut) to invoke your Zoombox.
it is annoying if you are jumpinng from record to record and
the zoombox keeps on popping on those hops.

TonC
09-29-2024, 02:41 AM
Hi june7,

When I go with my mouse, the arrow keys or tab key to the textbox in my subform, (onfocus) the text (is longer than the width of the textbox).

What happens is that de textbox not expand but my cursor goes to the end of my description, so far, so good.

But Its not what I want. I want to see the whole description what inside the textbox (visual from beginning till the end of the description)

not expand (lost focus)



Met access is het leuk




expand (on focus)



Met access is het leuk werken, moet ik wel even nadenken





Ill hope its clear for you, otherwise I dont know to explane my question.

Greetings

arnelgp
09-29-2024, 06:46 PM
you can also add an unbound textbox on the subform to show the Description.

TonC
09-30-2024, 06:31 AM
Hi arnelgp,

I did open your DB, and I was surprised to see saw that your subform was presented with form header en form footer.
Mine subform has no header and footer section, just a datasheet. Its is my mistake that wrote in my earlier post that my subform was a continious form. My apologies. It was not the solution I was looking for, but still it works fine and I used it in my DB.
I think perhaps it cannot be done to expand a textbox in a datasheet itself. (I don’t know)

I created in my mainform a textbox “Omschrijving” with the control source from my table. The control I made was is 15 cm width.
So your direction to make it work in my DB was for me the solution.

Thank you !!:thumb

arnelgp
09-30-2024, 08:44 PM
here is another demo. it will expand the Description column on the subform when you click or the column has focus.
it will go back to it's original column width when you leave the column.
open MainForm2 and see the code on Load event of subDatasheet subform and the Click, GotFocus, LostFocus of Description column.

TonC
10-01-2024, 03:03 AM
Hi VBAX Expert

I did open your DB, ther was a message
SECURITY PROBLEM “Microsoft blocked the performance of the macro’s, the source is not to be trusted.

So I did still opened your DB, It was not working. I don’t how to shut down the security problem. :crying:

TonC

TonC
10-01-2024, 03:54 AM
Hello VBAX Regular,
Your genius, It works!!!!!:bow::bow: I solved the security problem, put your code in my subfrm datasheet

Many thanks, this what I looked for.
Regard Tonc

arnelgp
10-01-2024, 04:44 AM
when you download any file from the internet, always right click on and on it's Property, tick Unblock.