
Unable to delete controls.
When deleting from a collection you should delete from the last to the
first.
so your code should be something like this
Public Sub Deletcontrols()
dim intX as integer
dim intCount as integer
Dim ctlText As Control
Dim strForm as string
dim loform as form
strFrom = "FrmTest"
DoCmd.OpenForm strForm, acDesign, , , , acHidden
set loform = Forms(strform)
intCount= loform.controls.count
for intX= (intCount -1) to 0 step -1
set ctltext=loform.controls(intX)
If ctlText.ControlType = acTextBox Then
DeleteControl strform, ctlText.Name
End If
Next
End sub
Quote:
>Hi there,
>I have a very strange problem.
>I need to delete all textboxes from a form (They are recreated based on the
>values in a table). When I run the following routine, some of the textboxes
>on my form are not deleted. I have to run the routine a couple of times
>before all textboxes are deleted.
>Am I missing something here?
>Public Sub Deletcontrols()
>Dim ctlText As Control
>Dim strForm as string
>strFrom = "FrmTest"
>DoCmd.OpenForm strForm, acDesign, , , , acHidden
>For Each ctlText In Forms(strform).Controls
> If ctlText.ControlType = acTextBox Then
> DeleteControl strform, ctlText.Name
> End If
>Next
>End sub
>Please reply to the Newsgroups and (if possible) to my e-mail address.
>Sven De Bont
>Tangram Data NV