How can I add a field to an existing form NOT a newly created form using VBA?
I currently have VBA code creating a new field in a table.
This table has an associated form.
I want this newly created table field to also appear in the form automatically through vba.
I tried to create a control to add to the form, but I keep getting an error message that says
"Run-time error '3799' Could not find Field 'Text14' "
My form is named "Table1" (for test purposes)
The field I am trying to add from my table is "field4"
I do not know why vba is looking for field "Text14", when I am adding "field4"
Here is my stripped down code:
Dim frm As Form
Dim ctrltext As Control
DoCmd.OpenForm "Table1", acDesign
Set ctrltext = CreateControl("Table1", acTextBox, acDetail, "", "field4")
DoCmd.Restore
DoCmd.Close
End Sub
The below code works with creating a NEW form, but does not work with an existing form
Sub NewControls()
Dim frm As Form
Dim ctlLabel As Control, ctlText As Control
Dim intDataX As Integer, intDataY As Integer
Dim intLabelX As Integer, intLabelY As Integer
' Create new form with Orders table as its record source.
Set frm = CreateForm
frm.RecordSource = "Orders"
' Set positioning values for new controls.
intLabelX = 100
intLabelY = 100
intDataX = 1000
intDataY = 100
' Create unbound default-size text box in detail section.
Set ctlText = CreateControl(frm.Name, acTextBox, , "", "", _
intDataX, intDataY)
' Create child label control for text box.
Set ctlLabel = CreateControl(frm.Name, acLabel, , _
ctlText.Name, "NewLabel", intLabelX, intLabelY)
' Restore form.
DoCmd.Restore
End Sub
Any help would be appreciated