MS Access resize fields within a form is really handy when you publish a Microsoft Access program. Different users have different monitors and different resolutions. Therefore, you might need to facilitate your program with a feature that resized any text boxes or even buttons or font size to fit the screen of the final user.
How to resize fields within a form
For simplicity, we are attaching a downloadable sample of the main subject to MS Access Resize Fields Within a Form. There you will find some VBA codes and a module to resize any kind of properties. A sample of these codes to resize a field shown below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Public Sub ToSize(btnName, frmName As String) Dim strFormName As String strFormName = frmName Select Case btnName Case Is = "Up" Call SizeHeight(1.1, strFormName) Case Is = "Down" Call SizeHeight(-1.1, strFormName) Case Is = "Left" Call SizeWidth(-1.2, strFormName) Case Is = "Right" Call SizeWidth(1.2, strFormName) Case Is = "OK" DoCmd.Close acForm, frmName, acSaveNo End Select End Sub |
The below VBA code shows an example to resize the height of a field:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
Sub SizeHeight(x As Double, frmName As String) Dim intH, intFont As Double If x < 0 Then intH = Val(Forms(frmName).Text1.Height) / x * (-1) intFont = Val(Forms(frmName).Text1.FontSize) + 1 Else intH = Val(Forms(frmName).Text1.Height) * x intFont = Val(Forms(frmName).Text1.FontSize) - 1 End If DoCmd.Close acForm, frmName, acSaveYes DoCmd.OpenForm frmName, acDesign, , , acFormEdit, acHidden Dim ctl As Control For Each ctl In Forms(frmName).Form.Controls If TypeOf ctl Is TextBox Then ctl.Height = intH ctl.FontSize = intFont End If Next ctl DoCmd.Close acForm, frmName, acSaveYes DoCmd.OpenForm frmName End Sub |
Likewise, the width of fields can be resized the same way as the above VBA code.
Just Download our example and you will discover the codes.
To use Microsoft Access Programs.
You’ll need to have Microsoft Office installed including the bundle of MS Access or to download the free Microsoft Access 2016 run-time.
Please check our Pro Microsoft Access Programs here.