Skip to content

Instantly share code, notes, and snippets.

@felixlindemann
Last active March 1, 2021 12:50
Show Gist options
  • Save felixlindemann/12da432d706f64fd220a to your computer and use it in GitHub Desktop.
Save felixlindemann/12da432d706f64fd220a to your computer and use it in GitHub Desktop.
VBA: Create Userform in MS-Access Programatically - Demo
Public Sub demo_Modul_Userform()
Dim frm As Object
Set frm = getEmptyForm()
frm.Properties("Height") = 100
frm.Properties("Width") = 200
'add control
Dim NewButton As Msforms.CommandButton
Set NewButton = frm.Designer.Controls.Add("Forms.CommandButton.1")
With NewButton
.Caption = "Click Me"
.Left = 60
.Top = 40
End With
With frm.CodeModule
Line = .CountOfLines
.InsertLines Line + 1, "Sub " & NewButton.Name & "_Click()"
.InsertLines Line + 2, " call demo_Modul_Userform_CommandButtonAction"
.InsertLines Line + 3, "End Sub"
End With
showForm frm
closeForm frm
End Sub
Public Sub demo_Modul_Userform_CommandButtonAction()
MsgBox "Hello World"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment