Unable to delete controls. 
Author Message
 Unable to delete controls.

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



Sat, 01 Jul 2000 03:00:00 GMT  
 Unable to delete controls.

I think this is because after deleting control you need to refresh
collection (or something like this)
I do this procedure within loop:

Quote:
>Public Sub Deletcontrols()

>Dim ctlText As Control
>Dim strForm as string

DIM i
Quote:

>strFrom = "FrmTest"
>DoCmd.OpenForm strForm, acDesign, , , , acHidden
for i= 1 to 3
>For Each ctlText In Forms(strform).Controls
>   If ctlText.ControlType = acTextBox Then
>        DeleteControl strform, ctlText.Name
>   End If
>Next
next i
>End sub

Best regards,
___________
Alex Dybenko
Point Limited

Home Page: http://www.geocities.com/SiliconValley/Heights/5091/
Moscow MS Access User Group, chairman
http://www.arimsoft.ru/msaccess


Sat, 01 Jul 2000 03:00:00 GMT  
 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



Sat, 01 Jul 2000 03:00:00 GMT  
 Unable to delete controls.

Hi Sven,

You are accessing a container with the controls of your form. And you
are changing the contents during your loop.

Try something like: For i = 0 to form.Controls.Count - 1 Do

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

--
Rob Goudvis




Sun, 02 Jul 2000 03:00:00 GMT  
 Unable to delete controls.

Thanks Terry

Quote:

>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


>>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



Sun, 02 Jul 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Unable to delete controls.

2. Unable to delete and Excel Workbook from VBA

3. Unable to delete emails frm my inbox?

4. Unable to delete value in field bound to xs:decimal type

5. Unable to delete all records from a access database with ado

6. Unable to delete dll file

7. Unable to delete all records from access database with ado

8. Unable to delete from query if more than one table in query

9. Unable deleting a .mdb file

10. Deleting Controls does not delete form reference information

11. SQL delete query deletes but does not delete

12. Unable to set the volume on a specfied Multimedia control

 

 
Powered by phpBB® Forum Software