Share via

Create layout's table/cell in a Form using vba code

Anonymous
2020-01-20T00:27:30+00:00

How to create a layout in a Form using VBA. Thank you

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2020-01-21T01:56:14+00:00

Hi Timur

Following on from my previous code, lets say you add two combo's to the form. It needs to be in design mode and you also need to select each of the fields to add to the layout. So, if you look at the following code you should get an idea of what is required:

Dim frmNewForm As Access.Form

Dim ctlNewControl As Access.Control

Set frmNewForm = Application.Forms("form4")

Set ctlNewControl = CreateControl(frmNewForm.Name, acComboBox, acDetail, , , 250, 250, 1400, 500)

Set ctlNewControl = CreateControl(frmNewForm.Name, acComboBox, acDetail, , , 450, 450, 1400, 500)

DoCmd.OpenForm "form4", acDesign

Dim ctl As Control

For Each ctl In frmNewForm

ctl.InSelection = True

Next ctl

RunCommand acCmdStackedLayout

This adds both combo's to a stacked layout.

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2020-01-20T11:21:14+00:00

To add controls and position controls the form needs to be open and in design mode. For instance to add a control to a form (form4) it needs to be in design mode and ode similar to the following used:

Private Sub cmdCreateControls_Click()

Dim frmNewForm As Access.Form

Dim ctlNewControl As Access.Control

Set frmNewForm = Application.Forms("form4")

Set ctlNewControl = CreateControl(frmNewForm.Name, acComboBox, acDetail, , , 250, 250, 1400, 500)

End Sub

This will add a combo box at the coordinated given.

To create a form you would use something like:

Private Sub cmdCreateForm_Click()

Dim frmNewForm As Access.Form

Set frmNewForm = CreateForm()

frmNewForm.Caption = "My New Form"

DoCmd.MoveSize 500, 500, 8000, 4000

DoCmd.Save acForm, frmNewForm.Name

End Sub

Is that something like what you are looking to do?

Personally I can't understand the purpose... seems like a lot of work

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2020-01-20T05:09:20+00:00

Hi Timur, if you have 'lot of forms'and they are all different, how much time do you think it will take to write code and work out coordinates of controls, resize forms to 'automate' the process versus doing it manually. Also you don't use rows and columns in forms unless it's a list box or continuous form nor do you 'place controls inside a cell'

If you have spent time on a design for your project you should really only have to do things once and make maybe a few finer adjustments later on.

Access is not Excel. I think you need to hit the books and do a bit of research on MS Access first.

Was this answer helpful?

0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2020-01-20T13:49:12+00:00

    I have already created forms and controls (texbox, combobox ...). I calculate position "Left", "Top" and "Wight". I need to manually move, resize the controls in each forms.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2020-01-20T09:09:53+00:00

    I'm creating a form. Put control and set "top", "left", "wight". But with "CreateControl" no layout is in a Form. How to create a layout on a form using vba?

    Was this answer helpful?

    0 comments No comments