stevenblanc
Registered User.
- Local time
- Today, 14:23
- Joined
- Jun 27, 2011
- Messages
- 103
Hi folks,
So now we've having tons of fun. The folks here need to be able to add, edit, and remove records which relate to pedagogical items on a whim. There is no scenario where the number of these items will ever exceed 75.
These items are then used to create table columns on a separate table. This also means that the user entry form must be updated to reflect these fields.
Right now I'm able to pull the names and build the fields dynamically; however, I'm having a problem removing them:
Most of the controls disappear but I have two columns of textboxes that just wont go, even though their names match the criteria. This creates a problem when creating the new controls.
The full code is as follows:
The controls offending controls are all dyntxtGuide(i) and dytxtNotePed(i).
Any ideas?
So now we've having tons of fun. The folks here need to be able to add, edit, and remove records which relate to pedagogical items on a whim. There is no scenario where the number of these items will ever exceed 75.
These items are then used to create table columns on a separate table. This also means that the user entry form must be updated to reflect these fields.
Right now I'm able to pull the names and build the fields dynamically; however, I'm having a problem removing them:
Code:
' Remove old controls
For Each ctl In Forms!form1.Controls
If left(ctl.Name, 3) = "dyn" Then ' All dynamically created controls will be identified by "dyn"
DeleteControl strForm, ctl.Name
End If
Next ctl
Most of the controls disappear but I have two columns of textboxes that just wont go, even though their names match the criteria. This creates a problem when creating the new controls.
The full code is as follows:
Code:
Dim i As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strForm As String
Dim frm As ACCESS.Form
Dim ctl, ctlLabel, ctlGuidePed, ctlNumPed, ctlTotalHrs, ctlNotePed As Control
Dim intDataX, intDataY, intDataHeight As Integer
Dim intLabelX, intLabelY As Integer
strForm = "form1"
Set db = CurrentDb
Set rs = db.OpenRecordset("tblGuidelines")
' Ensure loop starts at 0.
i = 0
' Set positioning values for new controls.
intLabelX = 100
intDataX = 2500
intDataY = 250
intDataHeight = 315
If booFormUpdated = False Then
DoCmd.OpenForm strForm, acLayout
' Remove old controls
For Each ctl In Forms!form1.Controls
If left(ctl.Name, 3) = "dyn" Then ' All dynamically created controls will be identified by "dyn"
DeleteControl strForm, ctl.Name
End If
Next ctl
'MsgBox "done" ' This msgbox is used to check the offending controls
DoCmd.OpenForm strForm, acDesign
' Ensure loop starts at 1 so that i matches [pedGuide].
i = 1
' Create and format new controls
Do While i <= rs.RecordCount
' Create textboxes for data in detail section.
Set ctlGuidePed = CreateControl(strForm, acTextBox, , "", "", intDataX, intDataY, 1700, intDataHeight)
Set ctlNumPed = CreateControl(strForm, acTextBox, , "", "", ctlGuidePed.Width + ctlGuidePed.left, intDataY, 1700, intDataHeight)
Set ctlTotalHrs = CreateControl(strForm, acTextBox, , "", "", ctlNumPed.Width + ctlNumPed.left, intDataY, 1700, intDataHeight)
Set ctlNotePed = CreateControl(strForm, acTextBox, , "", "", ctlTotalHrs.Width + ctlTotalHrs.left, intDataY, , intDataHeight)
' Create child label control for text box and lookup Pedagogy Title.
Set ctlLabel = CreateControl(strForm, acLabel, , ctlGuidePed.Name, DLookup("[pedTitle]", "[tblguidelines]", "[pedGuide] = " & i), intLabelX, intDataY)
booFormUpdated = True
' Set names for each created control based on i
ctlGuidePed.Name = "dyntxtGuide" & i
ctlNumPed.Name = "dyntxtPed" & i
ctlTotalHrs.Name = "dyntxtPed" & i & "Total"
ctlNotePed.Name = "dyntxtNotePed" & i
ctlLabel.Name = "dyntxtGuide" & i & "Title"
' Lookup pedagogy time guidelines
ctlGuidePed.DefaultValue = DLookup("[timeMins]", "[tblGuidelines]", "[pedGuide] = " & i)
ctlGuidePed.TextAlign = 2
' Adjust ctl formatting
ctlGuidePed.BorderStyle = 0
ctlTotalHrs.Enabled = False
' Set the next row to start right below the current
intDataY = intDataY + ctlGuidePed.height
i = i + 1
Loop
DoCmd.Close acForm, "form1", acSaveYes
DoCmd.OpenForm "form1", acNormal
End If
The controls offending controls are all dyntxtGuide(i) and dytxtNotePed(i).
Any ideas?
Last edited: