|
| Author |
Message |
Arch Stanton
Joined: 26 Nov 2007 Posts: 4
|
Posted: Mon Nov 26, 2007 2:18 am Post subject: Delete controls at run time? |
|
|
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 |
|
 |
Larry Serflaten
Joined: 04 Oct 2007 Posts: 2644
|
Posted: Mon Nov 26, 2007 11:51 am Post subject: Re: Delete controls at run time? |
|
|
"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 |
|
 |
Bob Butler
Joined: 04 Oct 2007 Posts: 1081
|
Posted: Mon Nov 26, 2007 10:53 am Post subject: Re: Delete controls at run time? |
|
|
"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 |
|
 |
Arch Stanton
Joined: 26 Nov 2007 Posts: 4
|
Posted: Mon Nov 26, 2007 11:47 am Post subject: Re: Delete controls at run time? |
|
|
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 |
|
 |
Arch Stanton
Joined: 26 Nov 2007 Posts: 4
|
Posted: Mon Nov 26, 2007 11:49 am Post subject: Re: Delete controls at run time? |
|
|
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 |
|
 |
Bob Butler
Joined: 04 Oct 2007 Posts: 1081
|
Posted: Mon Nov 26, 2007 12:03 pm Post subject: Re: Delete controls at run time? |
|
|
"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 |
|
 |
Jeff Johnson
Joined: 04 Oct 2007 Posts: 1327
|
Posted: Mon Nov 26, 2007 3:16 pm Post subject: Re: Delete controls at run time? |
|
|
"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 |
|
 |
Larry Serflaten
Joined: 04 Oct 2007 Posts: 2644
|
Posted: Mon Nov 26, 2007 7:54 pm Post subject: Re: Delete controls at run time? |
|
|
"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?
(As others have already indicated, Unload is a VB statement: Unload )
LFS |
|
| Back to top |
|
 |
Randy Birch
Joined: 04 Oct 2007 Posts: 1768
|
Posted: Mon Nov 26, 2007 11:44 pm Post subject: Re: Delete controls at run time? |
|
|
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 |
|
 |
Arch Stanton
Joined: 26 Nov 2007 Posts: 4
|
Posted: Mon Nov 26, 2007 10:28 pm Post subject: Re: Delete controls at run time? |
|
|
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?
>
> (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 |
|
 |
|