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" frmSub1.Controls will only delete 3. actually, if i start out with 0 controls on my form, the first run 0 will be deleted, and 6 made. second run, 3 will be deleted, 6 made (total = 9). third run, it will delete 5, add 6 (total = 10), same fourth run (tot=11), then stabilize on 6 deletions and 6 additions (tot=11) for every run after that... (when i want all to be deleted every time!)
why arent "For Each ctl In Forms!frmSub1.Controls" picking up all the controls?
thanks! -
Public Function makeArrows()
-
-
Dim lngColor As Long
-
Dim str1
-
Dim str2
-
Dim n As Integer
-
Dim RecSet As Recordset
-
Dim DatePoint As Recordset
-
-
Set DatePoint = CurrentDb.OpenRecordset("DatePointer")
-
Set RecSet = CurrentDb.OpenRecordset("CalQarrows")
-
lngColor = RGB(0, 255, 0)
-
-
-
c = DatePoint.Fields("RStartDate").Value 'access day# for manual datepicker in calendar
-
d = 0
-
-
'// some way of picking each room/subform
-
Forms!Calendar!ctrlSub1.SourceObject = ""
-
n = 1
-
str1 = "frmSub" & n
-
DoCmd.OpenForm str1, acDesign, , , acFormEdit, acHidden
-
'// delete all controls
-
Dim ctl As Control
-
o = 0
-
For Each ctl In Forms!frmSub1.Controls
-
o = o + 1
-
'MsgBox str1 & " / " & ctlDel.Name
-
'MsgBox str1
-
DeleteControl str1, ctl.Name
-
Next ctl
-
MsgBox o
-
-
Do Until RecSet.EOF
-
If RecSet.Fields("RoomNumber").Value = 105 Then
-
-
d = d + 1
-
-
a = (RecSet.Fields("SlotBegin").Value - c) * 1000
-
b = (RecSet.Fields("SlotLength").Value * 1000)
-
bookID = RecSet.Fields("Bookings.ID").Value
-
bookNameS = RecSet.Fields("NameString").Value
-
bookFullName = RecSet.Fields("LastName").Value & ", " & RecSet.Fields("FirstName").Value
-
bookDate = RecSet.Fields("INdate").Value & " @ " & RecSet.Fields("INtime").Value & " to " & RecSet.Fields("OUTdate").Value & " @ " & RecSet.Fields("OUTtime")
-
-
-
-
Set cImg1 = CreateControl(str1, acImage)
-
cImgn = cImg1.Name
-
Forms!frmSub1!(cImgn).BackStyle = 0
-
Forms!frmSub1!(cImgn).Width = 432
-
Forms!frmSub1!(cImgn).Height = 360
-
Forms!frmSub1!(cImgn).Left = a
-
Forms!frmSub1!(cImgn).Top = 0
-
Forms!frmSub1!(cImgn).ControlTipText = bookFullName
-
Forms!frmSub1!(cImgn).OnClick = ""
-
Forms!frmSub1!(cImgn).Picture = "C:\Users\Lailita\Documents\arrows\yellowA.png"
-
-
Set cImg2 = CreateControl(str1, acImage)
-
cImg2n = cImg2.Name
-
Forms!frmSub1!(cImg2n).BackStyle = 0
-
Forms!frmSub1!(cImg2n).Width = 432
-
Forms!frmSub1!(cImg2n).Height = 360
-
Forms!frmSub1!(cImg2n).Left = a + b
-
Forms!frmSub1!(cImg2n).Top = 0
-
Forms!frmSub1!(cImg2n).Picture = "C:\Users\Lailita\Documents\arrows\yellowAh.png"
-
-
Set cLbl1 = CreateControl(str1, acLabel)
-
cLbln = cLbl1.Name
-
Forms!frmSub1!(cLbln).Visible = True
-
Forms!frmSub1!(cLbln).BackColor = RGB(255, 194, 14)
-
Forms!frmSub1!(cLbln).ForeColor = RGB(255, 255, 255)
-
Forms!frmSub1!(cLbln).FontWeight = 900
-
Forms!frmSub1!(cLbln).TopMargin = 34
-
Forms!frmSub1!(cLbln).TextAlign = 2
-
Forms!frmSub1!(cLbln).BackStyle = 1
-
Forms!frmSub1!(cLbln).Top = 0
-
Forms!frmSub1!(cLbln).Height = 350
-
Forms!frmSub1!(cLbln).Left = a + 250
-
Forms!frmSub1!(cLbln).Width = b
-
Forms!frmSub1!(cLbln).Caption = bookNameS
-
Forms!frmSub1!(cLbln).ControlTipText = bookFullName & ": " & bookDate
-
-
End If
-
-
RecSet.MoveNext
-
Loop
-
MsgBox "no of recset loops is " & d
-
Dim ctlCheck As Control
-
p = 0
-
For Each ctlCheck In Forms!frmSub1.Controls
-
p = p + 1
-
'MsgBox str1 & " / " & ctlDel.Name
-
'MsgBox str1
-
'DeleteControl str1, ctl.Name
-
Next ctlCheck
-
MsgBox "total controls at build end is " & p
-
DoCmd.Close acForm, str1, acSaveYes
-
Forms!Calendar!ctrlSub1.SourceObject = str1
-
Sorry, I didn't have the correct syntax in front of me when I wrote the last post.
A small modification to your code if I may, to make it nicer: - Do While Forms(strFormName).Controls.Count > 0
-
DeleteControl strFormName, Forms(strFormName).Controls(1).Name
-
Loop
4 13426
Because imagine looping through an array of controls, where first you delete the first element, then proceed to delete the second element and so on. Problem is that as you delete the first element, the remaining controls "move down".
This behavior is something you need to be wary of, when using for each in combination with deletions and maybe also additions.
Instead you can use: - Do While Forms!frmSub1.Controls.Count>0
-
Forms.Controls(0).Delete
-
Loop
Maybe the 0 should be a 1, not 100% sure.
thanks, looks clean - but i get a object not supported for the .Delete line..?
but this worked now: -
Do While Forms!frmSub1.Controls.Count > 0
-
For Each ctl In Forms!frmSub1.Form.Controls
-
DeleteControl str1, ctl.Name
-
Next ctl
-
Loop
-
so thank you very much!!
Sorry, I didn't have the correct syntax in front of me when I wrote the last post.
A small modification to your code if I may, to make it nicer: - Do While Forms(strFormName).Controls.Count > 0
-
DeleteControl strFormName, Forms(strFormName).Controls(1).Name
-
Loop
NeoPa 32,534
Expert Mod 16PB
I don't know if performance is an issue, but to save the object references to be worked out each time through the loop : - With Forms(strFormName).Controls
-
Do While .Count > 0
-
Call DeleteControl(strFormName, .Item(0).Name)
-
Loop
-
End With
Sign in to post your reply or Sign up for a free account.
Similar topics
by: deko |
last post by:
I have a popup "Tools" form with a tab control that has a different subform
on each tab. The problem is that new tabs/subforms continue to be added as
users request new features - so the code on...
|
by: marc-andr? |
last post by:
Hi,
I have to loop on each control on a webforms...
I use this function :
public void LoopOnAllControls(ControlCollection coll)
{
foreach (System.Web.UI.Control ctrl in coll)
{
|
by: RC |
last post by:
Hi,
I am newbie on ASP.NET and VS.NET
I want to build a site with multiple dll of code-behind code for each web
form.
As I know each project build in VS.NET....all code-behind codes will be...
|
by: VJ |
last post by:
I have a MDI application with Child windows... On one specfic child window
if I click a Toolbar (part of the child window), I launch a Window that will
be child of the MDI and it comes up...
|
by: Shurik |
last post by:
Hey everyone,
Just run into an issue with ASP.NET 2.0 Image control... I assign CSS
style to it in HTML (CssClass="blah"), but when I hit the page with a
browser my style isn't used due to...
|
by: david.boone |
last post by:
Hello,
I am trying to enable controls based on the value of a checkbox, i.e.
if value = true then enable.
I have a tab control form with controls on 4 tabs. I have some code
(below) on the...
|
by: Filippo Bettinaglio |
last post by:
hi,
I have developed a window control form in C sharp 2005,
I can use the component in other .exe applications (just keeping the two
project in the same solution group file) but I cannot use it...
|
by: TonyMast |
last post by:
win forms - xp pro - vb 2005
Shouldn't this code look at all textboxes on my form and make it lightblue
and say "OK"?
It seems to be evaluating a button I have on the form and giving me this...
|
by: TerryStone |
last post by:
I have created a control that displays a list of items. During design
mode I fill it with junk data using calls from the constructor. So
when I look at a form with the control on, instead of...
|
by: GeoffT |
last post by:
I have encountered a problem with the data that is displayed in the list boxes that are located on a tab control access form (2003 version). This form uses several combo boxes as filters (After...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| | |