Access Tips – Using an Expanded Text Box
Open an Expanded Text form by right clicking on a text box. This is useful if you have a text box that may only display one or two lines of text and you can potentially have ten or twenty lines. Viewing in the expanded text box allows you to read the text and also enter or edit. The information in the expanded form is moved to the text box through a “Close and Update” button. There is also a “Cancel” button on the Expanded Text Form.
The following code goes in the main form, and is used to open the expanded text form.
Public Sub subOpenExpandedText() ‘Function to open the text input form on long text fields On Error Resume Next DoCmd.OpenForm “frmExpandedText” ‘ PASTE TO text box Mousedown Event ———————- ‘ Display bulk text input screen ‘ On Error Resume Next ‘ If (Button = acRightButton) Then ‘ DoCmd.RunCommand acCmdSaveRecord ‘ subOpenExpandedText ‘ End If ‘———–——————————————-End Sub |
The form to display expended text has a single text box called txtExpanded. It is around 17 cm wide and 8.5 cm high. There are two buttons. One is to “Close and Update” and the other to “Cancel”. Paste the following code into the form.
Option Compare Database Dim strText As String Dim intFieldLength As Integer Dim strFormName As String Dim Screen_ActiveSubformControl As Control‘+++++++++++++++ Start of Opening Actions ++++++++++++++++++++ ‘ Private Sub Form_Open(Cancel As Integer) ‘What : Function to get ready once opened. ‘ There is a problem if the subform name being passed belongs to a subform within a subform If (Me.OpenArgs & “” = “”) Then Set ctlCurrentControl = Forms(Screen.ActiveForm.Name)(Screen.ActiveControl.Name) Else If (Me.OpenArgs = Screen.ActiveForm.Name) Then Set ctlCurrentControl = Forms(Screen.ActiveForm.Name)(Screen.ActiveControl.Name) Else Set ctlCurrentControl = Forms(Screen.ActiveForm.Name)(Me.OpenArgs).Form(Screen.ActiveControl.Name) End If End If SkipsCtl: Me.txtExpanded = ctlCurrentControl End Sub ‘+++++++++++++++ Start of Closing Actions +++++++++++++++++++++ ‘++++++++++++ Start of Miscellaneous Buttons Click +++++++++++++++ If Not IsNull(Me.txtExpanded) Then strText = Me.txtExpanded ctlCurrentControl = strText End If DoCmd.Close Exit_btnClose_Click: Err_btnClose_Click: End Sub Private Sub btnCancel_Click() DoCmd.Close Exit_btnCancel_Click: Err_btnCancel_Click: End Sub ‘ ++++++++++++++ Start of Subs and Functions +++++++++++++++++++ If Set_Screen_ActiveSubformControl() = False Then Msg = “There is no active subform!” Else Msg = “Active Form Name = ” & Screen.ActiveForm.NameMsg = Msg & CR End If MsgBox Msg End Function Function Set_Screen_ActiveSubformControl() ‘ Clear the control variable. ‘ Assume a subform is not active. ‘ Get the active form and control. ‘ Get the unique window handle identifying the form ‘ If the active form window handle is the same as the window handle of the form the active control is on, then we are on the mainform, so ‘ exit. ‘ Find a subform control that has a window handle matching the window handle of the form the active control is on. End Function Function FindSubform(frmSearch As Form, hWndFind As Long) ‘ Assume we will find a subform control with a window handle matching hWndFind. ‘ Visit each control on the form frmSearch. Set Screen_ActiveSubformControl = frmSearch(I) Else ‘ If we found a subform control, then exit. If FindSubform(frmSearch(I).Form, hWndFind) Then Exit Function End If End If End If Bye_FindSubform: Err_FindSubForm: End Function |