I want to achieve the below tasks:
1. Create a form by VBA code
2. Dynamically add a control button to this form
3. Define the "Caption" for this button
4. Assign click event to this button
5. The click event is to delete the form itself
6. Form_Close() also delete the form itself
Now, only task 1 and 2 success, but don't know how to do task 3 to 6
Below is my code. Please help
The last 3 lines is use to rename the form only
1. Create a form by VBA code
2. Dynamically add a control button to this form
3. Define the "Caption" for this button
4. Assign click event to this button
5. The click event is to delete the form itself
6. Form_Close() also delete the form itself
Now, only task 1 and 2 success, but don't know how to do task 3 to 6
Below is my code. Please help

Code:
Sub CreateTmpForm()
Dim testfrm As Form
Dim ctlCloseBtn As Control
Dim frmOldName As String
Set testFrm = CreateForm
testFrm.Caption = "This is a test"
Set ctlCloseBtn = CreateControl(testFrm.Name, acCommandButton, , , , 4960, 1440, 960)
ctlCloseBtn.Name = "btnDelTmpFrm"
frmOldName = testFrm.Name
DoCmd.Close acForm, testFrm.Name acSaveYes
DoCmd.Rename "tmpForm", acForm, frmOldName
End Sub
The last 3 lines is use to rename the form only