473,473 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

deletecontrol issues

hello, so here is my problem... i wrote a function that opens a form,
and goes through all of the controls in the form, i check the first
letter of the name to see if it is an 'X', and if it is, then it
deletes the control. the problem is that it only deletes some of the
controls with names that start with an 'X'... now i wrote the program
so it looks for the 'X' because i couldnt figure out how to only look
at the controls in the details. if i could get it to, then all i would
need to do is tell it to delete ALL controls in the detail section...

the code...

Public Function clearForm()

Dim ctl As Control, ctls As Controls
Dim frm As Form
Dim x As String

DoCmd.openForm "JSA Form V2", acDesign

Set frm = Forms![JSA Form V2]
Set ctls = frm.Controls

For Each ctl In frm.Controls
x = Mid(ctl.Properties("Name"), 1, 1)
If x = "X" Then
DeleteControl frm.Name, ctl.Properties("Name")
End If
Next

DoCmd.Close acForm, "JSA Form V2", acSaveYes

End Function

after i run this function and open the form some of the controls are
gone, some are not... all of the controls in question were created in a
different function, all going through the same process... when i run
the function i notice that it doesnt even look at some of the
controls... it goes through all of the ones that i want to be left on
the form, and goes through and deletes a bunch of the ones its supposed
to... but it completely skips some, i dont understand why... they
appear in the form properties under the control section, they have the
correct name format (exactly the same as the ones that DO get
deleted)... but the for each loop doesnt look at them at all...

i would appreciate help in 1. figuring out how to run a deletecontrol
on only the controls in the details section or 2. figuring out why the
for each control in form.controls loop skips a bunch of the controls...

Jul 14 '06 #1
5 3912
wr***********@gmail.com wrote:
hello, so here is my problem... i wrote a function that opens a form,
and goes through all of the controls in the form, i check the first
letter of the name to see if it is an 'X', and if it is, then it
deletes the control. the problem is that it only deletes some of the
controls with names that start with an 'X'... now i wrote the program
so it looks for the 'X' because i couldnt figure out how to only look
at the controls in the details. if i could get it to, then all i would
need to do is tell it to delete ALL controls in the detail section...

the code...

Public Function clearForm()

Dim ctl As Control, ctls As Controls
Dim frm As Form
Dim x As String

DoCmd.openForm "JSA Form V2", acDesign

Set frm = Forms![JSA Form V2]
Set ctls = frm.Controls

For Each ctl In frm.Controls
x = Mid(ctl.Properties("Name"), 1, 1)
If x = "X" Then
DeleteControl frm.Name, ctl.Properties("Name")
End If
Next

DoCmd.Close acForm, "JSA Form V2", acSaveYes

End Function

after i run this function and open the form some of the controls are
gone, some are not... all of the controls in question were created in a
different function, all going through the same process... when i run
the function i notice that it doesnt even look at some of the
controls... it goes through all of the ones that i want to be left on
the form, and goes through and deletes a bunch of the ones its supposed
to... but it completely skips some, i dont understand why... they
appear in the form properties under the control section, they have the
correct name format (exactly the same as the ones that DO get
deleted)... but the for each loop doesnt look at them at all...

i would appreciate help in 1. figuring out how to run a deletecontrol
on only the controls in the details section or 2. figuring out why the
for each control in form.controls loop skips a bunch of the controls...
On the face of things it appears your code should work.

I might change it to

Set ctls = frm.Controls 'this line is unused, not needed

For Each ctl In frm.Controls
If Left(ctl.Name,1) = "X" then
DeleteControl frm.Name, ctl.name
endif
Next

From help topic Specifications it states:
"Number of controls and sections you can add over the lifetime of the
form or report 754"

Have you been deleting and adding lots of controls to the form? If so,
maybe 754 controls has been met and that throws off some things. As I
said, your code looks ok

You might want to do something like
For Each ctl In frm.Controls
If Left(ctl.Name,1) = "X" then
DeleteControl frm.Name, ctl.name
msgbox "Deleted " & ctl.Name
Else
msgbox "Kept " & ctl.Name
endif
Next
Jul 15 '06 #2
lol... made the changes you suggested... kept getting an error, the
thing was doing less than it had before. took a lil while, but i
figured it out... the program would delete the control, then try to
reference it when printing the message... so i reversed it so that it
printed the message than deleted it... i also made the change from
ctltext.properties("Name") to ctltext.Name throughout the rest of my
code... when i run the function it posts messages saying "kept" to all
the ones it should, and "deleted" to the ones that get deleted, but it
doesnt post even a message about the ones its supposed to delete but
doesnt... there arent many controls on this form, under 100...

i dont suppose you know if there is a way to tell it to simply delete
everything in the detail section... that is ultimately what im trying
to get it to do

Jul 18 '06 #3
found a way around it... i changed the way i named my textboxes so it
would just be = "TextBox" & num where num is a number from 1 to however
many i create... then when i go to delete them i dont use a for each...

i use for i = 1 to frm.count - 23 '23 = # of items other than the above
deletecontrol frm.name, "TextBox" & i
next i

Jul 18 '06 #4
Rather than repeatedly Creating then Deleting these controls, it may be
beneficial to leave a set hidden and ready on your form then unhide/rehide
as required using the Visible property.

You can manipulate the textbox on the fly, for example

with me.textbox01
.controlsource = "surname"
.left = 200
.top = 200
.visible = True
end with

then disengage it later with

me.textbox01.visible = false
me.textbox01.controlsource = ""
BTW, I suspect your initial problem was a refresh issue in that the
deletecontrol was affecting the frm.controls counter, hence apparently
skipping controls. You could try assembling the list of controls to delete
first perhaps in an array, then second pass through that array and delete
the controls. Although your last work-around looks good too!

Regards,
Kevin Rollo
Western Australia
--
Regards,
Kevin

<wr***********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
found a way around it... i changed the way i named my textboxes so it
would just be = "TextBox" & num where num is a number from 1 to however
many i create... then when i go to delete them i dont use a for each...

i use for i = 1 to frm.count - 23 '23 = # of items other than the above
deletecontrol frm.name, "TextBox" & i
next i
Jul 19 '06 #5
Hi,

The same problem occured to me...

To solve it you can test this:

j = Forms!IndicsARestituer.Count - 1

For i = j To 1 Step -1
If Left(Forms!IndicsARestituer(i).Name, 4) = "Niv_" Then
DeleteControl "IndicsARestituer",
Forms!IndicsARestituer(i).Name
End If
Next

I think the problem come from the change of the index of the control
when you use DeleteControl. So you have to begin from the end...

Regards,
Julien
Kevin Rollo a écrit :
Rather than repeatedly Creating then Deleting these controls, it may be
beneficial to leave a set hidden and ready on your form then unhide/rehide
as required using the Visible property.

You can manipulate the textbox on the fly, for example

with me.textbox01
.controlsource = "surname"
.left = 200
.top = 200
.visible = True
end with

then disengage it later with

me.textbox01.visible = false
me.textbox01.controlsource = ""
BTW, I suspect your initial problem was a refresh issue in that the
deletecontrol was affecting the frm.controls counter, hence apparently
skipping controls. You could try assembling the list of controls to delete
first perhaps in an array, then second pass through that array and delete
the controls. Although your last work-around looks good too!

Regards,
Kevin Rollo
Western Australia
--
Regards,
Kevin

<wr***********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
found a way around it... i changed the way i named my textboxes so it
would just be = "TextBox" & num where num is a number from 1 to however
many i create... then when i go to delete them i dont use a for each...

i use for i = 1 to frm.count - 23 '23 = # of items other than the above
deletecontrol frm.name, "TextBox" & i
next i
Jul 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom Loredo | last post by:
Hi folks- I'm about to move from a Solaris 8/SPARC environment to a Dell running RedHat 9. Are there any issues I need to be aware of in bringing my Python code over (mostly scientific...
28
by: grahamd | last post by:
Who are the appropriate people to report security problems to in respect of a module included with the Python distribution? I don't feel it appropriate to be reporting it on general mailing lists.
5
by: sandy | last post by:
Hi All, I am a newbie to MySQL and Python. At the first place, I would like to know what are the general performance issues (if any) of using MySQL with Python. By performance, I wanted to...
2
by: malcolm | last post by:
Hello, We have a robust (.NET 1.1 c# winforms) client-server application that utilizes many typed DataSets, typed DataTables and typed DataRows. Our application is a series of windows and popup...
1
by: GaryDean | last post by:
We have been developing all of our .net applications on 32 bit windows using 32 bit SQL Server. We are being asked to now deploy to servers running 64bit windows and 64bit SQL Server. Are there...
3
by: eschneider | last post by:
Just some common issues with WS: Using custom objects: When objects change, seems you are always fixing some issue. Update references, which sometimes does not work. Deployment: Weird errors...
4
Knut Ole
by: Knut Ole | last post by:
im trying to delete all existing controls in a form before creating new ones... however, it wont delete all the controls. for every code run i create 6 controls, but for every run the "For Each"...
16
Knut Ole
by: Knut Ole | last post by:
I have a function to draw some shapes on a form depending on values in queries/tables. The whole procedure takes up to ten seconds however, and as I'm new to coding, I assume I might have a lot to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.