VBA example - Microsoft Access: maximize form and controls


VBA Maximize Form and Controls

In this example, you will learn VBA Docmd.Maximize method to open a form in full screen mode. The Controls collection is used to access the controls that are placed on the form. The controls will be moved to the middle of the form except title Label(Name: lbltitle).  In addition, the font name and font size of the controls are set to Times New Roman and 15 (respectively). You will need to create and design a form as shown below.

 VBA example - Microsoft Access VBA Domcmd and Control(s) Student Form  

The VBA code for this example: 

Option Explicit

Option Compare Database

Private Sub Form_Load()

' Open form in full screen

DoCmd.Maximize

lblTitle.FontSize = 30 ' Title text

' Move controls to the middle of the form

Dim i As Integer

Dim cnt As Control

Dim t As Integer

Dim l As Integer

For i = 0 To Controls.Count - 1

Set cnt = Controls.Item(i)

If cnt.Name <> "lblTitle" Then

t = cnt.Top

l = cnt.Left

cnt.Move l + 3500, t + 600

cnt.Width = 5000  ' Expand the controls

cnt.FontName = "Times New Roman" 

cnt.FontSize = 15

End If

Next

End Sub



Comments

Dhafer al sarraf comment

 Dhafer al sarraf

Fantastic
Since long time i am looking for somthing like this website
Thank you very much


2016-11-07



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.