Home - Microsoft Access Development - Microsoft Access Tips
The following are some samples of VBA code that may prove useful.
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 ++++++++++++++++++++ ' There is a problem if the subform name being passed belongs
to a subform within a subform If (Me.OpenArgs & "" = "") Then SkipsCtl: Me.txtExpanded = ctlCurrentControl End Sub '+++++++++++++++
Start of Closing Actions +++++++++++++++++++++ '++++++++++++
Start of Miscellaneous Buttons Click +++++++++++++++
Exit_btnClose_Click:
Err_btnClose_Click: Private Sub btnCancel_Click() DoCmd.Close Exit_btnCancel_Click: Err_btnCancel_Click: ' ++++++++++++++
Start of Subs and Functions +++++++++++++++++++ If Set_Screen_ActiveSubformControl() = False Then 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 ' Find a subform control that has a window handle matching the End Function Function FindSubform(frmSearch As Form, hWndFind As Long) ' Assume we will find a subform control with a window ' Visit each control on the form frmSearch. '
If we found a subform control, then exit. Bye_FindSubform: Err_FindSubForm: End Function |
![]()