How MAARS creates the Dashboard Form programmatically using VBA

This function will ask the user to provide a name for the application dashboard and it will create the form, set the height to 4 inches tall. It only creates the form by using another form called “frmBlankForm” as a template and does not add any controls to the dashboard form.

Public Function CreateDashboardForm() As String
' Purpose: This function creates a new MS Access Form to be used as the Dashboard in MAARS, using VBA by copying another form
 ' Change the data source fo the new created form to the given table in tblName
 
 Dim frm As Form, frmNameJustCreated As String, frmNameFinal As String
 'Ask the user for the name of the dashboard form
 
 tblName = InputBox("Please enter the name of your new dashboard form", "Create New Generic Form", "Dashboard")

 frmNameFinal = "frm" & tblName
 
 If tblName = "" Then ' If the user did not give a name, exit the function
    CreateNewGenericForm = ""
    Exit Function
 Else
 
 If formExistsInTheDatabase(frmNameFinal) Then ' Another form already exists with the given name, so just inform the user
    MsgBox frmNameFinal & " already exists in the database"
    'DoCmd.DeleteObject acForm, frmNameJustCreated
 Else
    Set frm = CreateForm(, "frmBlankForm")
    frmNameJustCreated = frm.Name ' Create the new form as Form1 or Form2 etc.
    'MsgBox frmNameJustCreated
    
    With frm
        '.RecordSource = tblName
        .Width = 1440 * 11
        .Section(0).Height = 1440 * 4 ' Form Detail - set the height to 4 inch
        .Section(1).Visible = True  ' Form Header
        .Section(1).Height = 400 ' Form Header
        '.Section(1).DisplayWhen = 0  ' Form Header
        '.Section(2).Height = 100 ' Form Footer
        
    End With
    
    DoCmd.Save acForm, frmNameJustCreated
    DoCmd.Close acForm, frmNameJustCreated
    DoCmd.Restore
    DoCmd.Rename frmNameFinal, acForm, frmNameJustCreated
    CreateDashboardForm = frmNameFinal
    
 End If
 
 End If
 
End Function

This is a complimentary article written by the MAARS team for the MAARS user community. Code in this article drives the operation of MAARS (MS Access Application wRiting Software). MAARS is an intelligent automation program that speeds up MS Access Application Development by 10x, 20x or 100x times. To learn more about MAARS, click here.

Disclaimer:

Some information included in this article may have been sourced from other publicly available websites and blogs. In such cases, credit goes to those authors for the original ideas and thoughts, but we do take credit for putting valuable information together and improve the efficiency of other office developers.