msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Delete controls at run time?

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax
Author Message
Arch Stanton



Joined: 26 Nov 2007
Posts: 4

PostPosted: Mon Nov 26, 2007 2:18 am    Post subject: Delete controls at run time? Reply with quote

I'm using VB6 connected to Access via ADO.

My code creates an array of check boxes at run time based on the results
of a query using this code:

Load chkProject(intCounter)
With chkProject(intCounter)
.Visible = True
.Caption = rstSearchResults("DataSource")
.Top = chkProject(intCounter - 1).Top + 300
End With

My problem is that the second time I try this I get a message telling me
that it can't create the controls because they already exist, which is
true. Is there a way to remove these check boxes programmatically when
I'm done with them?

Thanks for any help.

Archived from group: microsoft>public>vb>syntax
Back to top
View user's profile Send private message
Larry Serflaten



Joined: 04 Oct 2007
Posts: 2644

PostPosted: Mon Nov 26, 2007 11:51 am    Post subject: Re: Delete controls at run time? Reply with quote

"Arch Stanton"

> My code creates an array of check boxes at run time based on the results
> of a query using this code:

> My problem is that the second time I try this I get a message telling me
> that it can't create the controls because they already exist, which is
> true. Is there a way to remove these check boxes programmatically when
> I'm done with them?

For each control you created using Load, you can remove using Unload.

LFS
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1081

PostPosted: Mon Nov 26, 2007 10:53 am    Post subject: Re: Delete controls at run time? Reply with quote

"Arch Stanton" wrote in message @comcast.com...
> I'm using VB6 connected to Access via ADO.
>
> My code creates an array of check boxes at run time based on the results
> of a query using this code:
>
> Load chkProject(intCounter)
> With chkProject(intCounter)
> .Visible = True
> .Caption = rstSearchResults("DataSource")
> .Top = chkProject(intCounter - 1).Top + 300
> End With
>
> My problem is that the second time I try this I get a message telling me
> that it can't create the controls because they already exist, which is
> true. Is there a way to remove these check boxes programmatically when I'm
> done with them?

You can Unload them or you can revise your creation code to not load them if
they are already there. assuming you have a contiguous array of controls:

if intCounter>chkProject.Ubound then Load chkProject(intCounter)

Note that if your second pass may have fewer controls than the first pass
then you may need to hide the extras:
for x=intCounter+1 to chkProject.UBound
chkProject(x).Visible=false
next
Back to top
View user's profile Send private message
Arch Stanton



Joined: 26 Nov 2007
Posts: 4

PostPosted: Mon Nov 26, 2007 11:47 am    Post subject: Re: Delete controls at run time? Reply with quote

Bob Butler wrote:
> "Arch Stanton" wrote in message
> @comcast.com...
>> I'm using VB6 connected to Access via ADO.
>>
>> My code creates an array of check boxes at run time based on the
>> results of a query using this code:
>>
>> Load chkProject(intCounter)
>> With chkProject(intCounter)
>> .Visible = True
>> .Caption = rstSearchResults("DataSource")
>> .Top = chkProject(intCounter - 1).Top + 300
>> End With
>>
>> My problem is that the second time I try this I get a message telling
>> me that it can't create the controls because they already exist, which
>> is true. Is there a way to remove these check boxes programmatically
>> when I'm done with them?
>
> You can Unload them or you can revise your creation code to not load
> them if they are already there. assuming you have a contiguous array of
> controls:
>
> if intCounter>chkProject.Ubound then Load chkProject(intCounter)
>
> Note that if your second pass may have fewer controls than the first
> pass then you may need to hide the extras:
> for x=intCounter+1 to chkProject.UBound
> chkProject(x).Visible=false
> next
>
>
Thanks, Bob. I'll use the workaround, but I tried this syntax:

chkProject(intcounter).Unload

And it gave me the "Data member not found" error. Also, VB doesn't offer
me the 'Unload' option when I type the period after the control name. Am
I using the wrong syntax?
Back to top
View user's profile Send private message
Arch Stanton



Joined: 26 Nov 2007
Posts: 4

PostPosted: Mon Nov 26, 2007 11:49 am    Post subject: Re: Delete controls at run time? Reply with quote

Larry Serflaten wrote:
> "Arch Stanton"
>
>> My code creates an array of check boxes at run time based on the results
>> of a query using this code:
>
>> My problem is that the second time I try this I get a message telling me
>> that it can't create the controls because they already exist, which is
>> true. Is there a way to remove these check boxes programmatically when
>> I'm done with them?
>
> For each control you created using Load, you can remove using Unload.
>
> LFS
>
>
VB doesn't offer me the 'Unload' option when I type the period after the
control name, and this syntax give me a "Data member not found' error:

chkProjects(intCounter).unload

Am I using the wrong syntax?
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1081

PostPosted: Mon Nov 26, 2007 12:03 pm    Post subject: Re: Delete controls at run time? Reply with quote

"Arch Stanton" wrote in message @comcast.com...
> Thanks, Bob. I'll use the workaround,

I wouldn't call either approach a workaround; just different ways to
accomplish the same effect

> but I tried this syntax:
>
> chkProject(intcounter).Unload
>
> And it gave me the "Data member not found" error. Also, VB doesn't offer
> me the 'Unload' option when I type the period after the control name. Am I
> using the wrong syntax?

Unload chkProject(intCounter)
Back to top
View user's profile Send private message
Jeff Johnson



Joined: 04 Oct 2007
Posts: 1327

PostPosted: Mon Nov 26, 2007 3:16 pm    Post subject: Re: Delete controls at run time? Reply with quote

"Arch Stanton" wrote in message @comcast.com...

> VB doesn't offer me the 'Unload' option when I type the period after the
> control name, and this syntax give me a "Data member not found' error:
>
> chkProjects(intCounter).unload
>
> Am I using the wrong syntax?

Since you used

Load chkProjects(intCounter)

why wouldn't you assume the opposite was

Unload chkProjects(intCounter)
Back to top
View user's profile Send private message
Larry Serflaten



Joined: 04 Oct 2007
Posts: 2644

PostPosted: Mon Nov 26, 2007 7:54 pm    Post subject: Re: Delete controls at run time? Reply with quote

"Arch Stanton" wrote

> > For each control you created using Load, you can remove using Unload.
> >
> VB doesn't offer me the 'Unload' option when I type the period after the
> control name,

And it doesn't offer you the Load option either, does it? Wink

(As others have already indicated, Unload is a VB statement: Unload )

LFS
Back to top
View user's profile Send private message
Randy Birch



Joined: 04 Oct 2007
Posts: 1768

PostPosted: Mon Nov 26, 2007 11:44 pm    Post subject: Re: Delete controls at run time? Reply with quote

Unload is a method, so call it as such ...

Unload ctl(x)

--


Randy Birch
http://vbnet.mvps.org/

Please respond to the newsgroups so all can benefit.


"Arch Stanton" wrote in message @comcast.com...
Bob Butler wrote:
> "Arch Stanton" wrote in message
> @comcast.com...
>> I'm using VB6 connected to Access via ADO.
>>
>> My code creates an array of check boxes at run time based on the
>> results of a query using this code:
>>
>> Load chkProject(intCounter)
>> With chkProject(intCounter)
>> .Visible = True
>> .Caption = rstSearchResults("DataSource")
>> .Top = chkProject(intCounter - 1).Top + 300
>> End With
>>
>> My problem is that the second time I try this I get a message telling
>> me that it can't create the controls because they already exist, which
>> is true. Is there a way to remove these check boxes programmatically
>> when I'm done with them?
>
> You can Unload them or you can revise your creation code to not load
> them if they are already there. assuming you have a contiguous array of
> controls:
>
> if intCounter>chkProject.Ubound then Load chkProject(intCounter)
>
> Note that if your second pass may have fewer controls than the first
> pass then you may need to hide the extras:
> for x=intCounter+1 to chkProject.UBound
> chkProject(x).Visible=false
> next
>
>
Thanks, Bob. I'll use the workaround, but I tried this syntax:

chkProject(intcounter).Unload

And it gave me the "Data member not found" error. Also, VB doesn't offer
me the 'Unload' option when I type the period after the control name. Am
I using the wrong syntax?
Back to top
View user's profile Send private message
Arch Stanton



Joined: 26 Nov 2007
Posts: 4

PostPosted: Mon Nov 26, 2007 10:28 pm    Post subject: Re: Delete controls at run time? Reply with quote

Larry Serflaten wrote:
> "Arch Stanton" wrote
>
>>> For each control you created using Load, you can remove using Unload.
>>>
>> VB doesn't offer me the 'Unload' option when I type the period after the
>> control name,
>
> And it doesn't offer you the Load option either, does it? Wink
>
> (As others have already indicated, Unload is a VB statement: Unload )
>
> LFS
>
>
>
Yep, put in about ninety hours over the T-day holiday on this, and I was
starting to see pink elephants on Sunday evening. Dumb mistake, thanks
for being so nice about it!

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group