Hi,
Looking only at your first question:
Having a quick Google for creating objects in VBA for MS Access I found some code that works, but it seems that it can't be used to update the form you are running from... So perhaps this doesn't help you.
Does anyone know how to do this on the current form you have the code running in?
An alternative may be to have the text boxes already created on your form, but have the Visible property set to No until you need to display them.
Anyway, here is the code for what it is worth. It is assumed that the code is called from a form other than the one that the code references (test_form). I tried this (in MS Access 2003) and it worked fine.
- Private Sub MakeATextBox()
-
' Creates a text box of the name "tbxTest" using the control source "txtTest"
-
' The text box is 1 in wide, 2 inches high, placed 0.5 inches from the
-
' top and left of the detail
-
-
Const TWIPS As Integer = 1440 ' text box dimensions are in twips
-
Dim ctl As Control
-
Dim intLeft As Integer
-
Dim intTop As Integer
-
Dim intWidth As Integer
-
Dim intHeight As Integer
-
intLeft = 0.5 * TWIPS
-
intTop = 0.5 * TWIPS
-
intWidth = 1 * TWIPS
-
intHeight = 2 * TWIPS
-
-
DoCmd.OpenForm "test_form", acDesign
-
Set ctl = CreateControl("test_form", acTextBox, acDetail, , "txtDesc1", intLeft, intTop, intWidth, intHeight)
-
-
ctl.Name = "tbxTest"
-
DoCmd.Close acForm, "test_form", acSaveYes
-
End Sub
-
-
' Call the code from where ever it is needed.
-
MakeATextBox