By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,476 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,476 IT Pros & Developers. It's quick & easy.

messing around with the item ordering of a Collection - the Controls one, specifically

P: n/a
hey guys,

Question about the internal workings of Access. How are controls added
in the Form.Controls collection? I mean, in which order?
the order place them on the form? is there a way to re-arrange them as
i please? My solution is to remove the objects from the Form.Controls
collection, place them in a tmpCollection, arrange tmpCollection as I
please, and then re-add them back into the Form.Controls collection.
thanks
Btw, is there any tools that let you comment blocks of code at a time?
i'm tired of doing it by hand?

-><-
Ghost In My Shell

Nov 13 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
I don't know about the first question, but may be able to help with the
second one. At least in Access 2003, in the code editor go to View|Toolbars
and select the Edit toolbar. It will have two buttons for Comment and
Uncomment Block. Highlight the desired code and click the button.

--
Wayne Morgan
MS Access MVP
<Pr**********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
hey guys,

Question about the internal workings of Access. How are controls added
in the Form.Controls collection? I mean, in which order?
the order place them on the form? is there a way to re-arrange them as
i please? My solution is to remove the objects from the Form.Controls
collection, place them in a tmpCollection, arrange tmpCollection as I
please, and then re-add them back into the Form.Controls collection.
thanks
Btw, is there any tools that let you comment blocks of code at a time?
i'm tired of doing it by hand?

-><-
Ghost In My Shell

Nov 13 '05 #2

P: n/a
Pr**********@gmail.com wrote:
hey guys,

Question about the internal workings of Access. How are controls added
in the Form.Controls collection? I mean, in which order?
the order place them on the form? is there a way to re-arrange them as
i please? My solution is to remove the objects from the Form.Controls
collection, place them in a tmpCollection, arrange tmpCollection as I
please, and then re-add them back into the Form.Controls collection.
thanks
Btw, is there any tools that let you comment blocks of code at a time?
i'm tired of doing it by hand?


I sense a certain relation between these two issues. What are you doing?
I have been fairly busy creating and manipulating controls in a form.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #3

P: n/a
nope, no relation between the two.

i wish i had copied the .adp file to my usb stick, so i could show
you...
I sure would love to have a pier review of my code... Hmm... I'll post
it on monday.

Ok, here's the basic idea.
I'm the Junior Code Monkey[tm] at work. I'm a lazy fuck, in the Larry
Wall/Perl lazy fuck way :) .So, instead of doing something like
With rs
.. AddNew
..Fields("ID") = textbox.Value
<blahblahblah>
..Update
End With

i did this (Thanks go out to cubert in EFnet #VisualBasic):

For each tmpControl in Form.Controls

if( typeof tmpControl is label or typeof tmpControl is label ) then
<code here>
elseif( typeof tmpControl is TextBox ) then
rs.Fields(tmpControl.Name) = tmpControl.Value
elseif( typeof tmpControl is ComboBox ) then
' column 0 is the id field in my controls
rs.Fields(tmpControl.Name) = tmpControl.Column( 0, tmpControl.ListInex)
elseif( typeof tmpControl is commandbutton ) then
<code here>

.....
else
' i fucked up, somewhere

end if

rs.Update

I got yelled at :`(

Head Code Monkey wants me to do it this way

With rs
..AddNew
..Fields![ID] = frmMyForm.Controls("ID").Value
..Fields![Name] = frmMyForm.Controls("Name").Value
<etc, etc, for all controls of the form>
..Update
End with

he keeps insisting that his way is the correct way of doing things and
it gives you complete control of your code and, "dog gone is, i do it
this way so, so will you!"

I think his way is stupid, because you'll have to mess with the code
each time you add a control.

bah, i think he's a fucking moron. I think my way rules, because i'll
never have to mess with the code ever again in order to write a record
into the db. What do you think?

Nov 13 '05 #4

P: n/a
Pr**********@gmail.com wrote:

Ump! I'm not a native speaker!
I sure would love to have a pier review of my code... Hmm... I'll post
it on monday.
Is that "peer review"? I certainly don't want to leave the impression of
over-correcting, just making sure I understand.
I'm the Junior Code Monkey[tm] at work. I'm a lazy fuck, in the Larry
Wall/Perl lazy fuck way :)
Lazy people have to be inventive such as to circumvent the sweat labor!
With rs
. AddNew
.Fields("ID") = textbox.Value
<blahblahblah>
.Update
End With
Looks to me as a manual lot of code in an unbound form to do what a
bound form can do. Is that it?
For each tmpControl in Form.Controls

if( typeof tmpControl is label or typeof tmpControl is label ) then
elseif( typeof tmpControl is TextBox ) then
rs.Fields(tmpControl.Name) = tmpControl.Value
What is the double test for? I see no difference

What about a

Select Case tmpControl.controltype
case actextbox
case accombobox, aclistbox
case else
end select

?
I got yelled at :`(

Head Code Monkey wants me to do it this way

With rs
.AddNew
.Fields![ID] = frmMyForm.Controls("ID").Value
.Fields![Name] = frmMyForm.Controls("Name").Value
<etc, etc, for all controls of the form>
.Update
End with
Is this code local to the form, or in some module? Addressing the
controls through the Controls collection always looks a bit overdone to me.
he keeps insisting that his way is the correct way of doing things and
it gives you complete control of your code and, "dog gone is, i do it
this way so, so will you!"
I fail to see that as "the correct way". It depends.
I think his way is stupid, because you'll have to mess with the code
each time you add a control.
If you get payed for it... of course you're right, double work lures. I
like the "open approach", but it shall not bother me with extra bookkeeping.
bah, i think he's a fucking moron. I think my way rules, because i'll
never have to mess with the code ever again in order to write a record
into the db. What do you think?


Your expression is, as Spock might say, emotional; but I agree with your
point. I don't see yet why this isn't handled in the form itself, that
is simpler. You don't have to write code at all to have values enter the
table.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #5

P: n/a

Bas Cost Budde wrote:
Is that "peer review"? I certainly don't want to leave the impression of over-correcting, just making sure I understand. Bones... I... am... running... out... of... greek... coffee...
must... refill ... intraveinous... coffee... sollution...
(yeah, you're correct. i got the SpellingMistake Desease :) )
Lazy people have to be inventive such as to circumvent the sweat labor!
With rs
. AddNew
.Fields("ID") = textbox.Value
<blahblahblah>
.Update
End With
Looks to me as a manual lot of code in an unbound form to do what a
bound form can do. Is that it?


yup. Head Code Monkey[tm] favors lots of manual labor like that.

What is the double test for? I see no difference

What about a

Select Case tmpControl.controltype
case actextbox
case accombobox, aclistbox
case else
end select
eh, it's the same deal. the difference is that before you mentioned the
..ControlType property, I never new it existed. :)
The reason I'm using multiple IFs is that i'm doing some manipulation
of some labels to let my users feel all nice about themselves >:) ("YOU
HAVE ENTERED A NEW RECORD!")
?
I got yelled at :`(

Head Code Monkey wants me to do it this way

With rs
.AddNew
.Fields![ID] = frmMyForm.Controls("ID").Value
.Fields![Name] = frmMyForm.Controls("Name").Value
<etc, etc, for all controls of the form>
.Update
End with
Is this code local to the form, or in some module? Addressing the
controls through the Controls collection always looks a bit overdone

to me.
my code is local to the form. i got a module (which i should turn into
a class some time in the future) but only things that more than 1 form
uses go there (like my emtpyRowSources( byref tmpForm as Form) )

By the way, what's wrong with passing forms and objects by reference?
Head Code Monkey insists its the wrong way to do things and that's it's
memory intensive. I'm like "Chill man, I'm passing a pointer, not the
whole object"
I fail to see that as "the correct way". It depends. Yeah, i know. in programming there is no "correct way"...
Your expression is, as Spock might say, emotional; but I agree with your point. I don't see yet why this isn't handled in the form itself, that is simpler. You don't have to write code at all to have values enter the table.

Boss loves unbound forms. He insists we use unbound forms. if he let me
use bound forms, this project would be over 2 months ago. that's why i
had to learn how to manipulate a form by hand. As for emotional, heh,
I'm Greek ^_^

Thanks,
George

Nov 13 '05 #6

P: n/a
Pr**********@gmail.com wrote:
(yeah, you're correct. i got the SpellingMistake Desease :) )
I like that :-)
Looks to me as a manual lot of code in an unbound form to do what a
bound form can do. Is that it?


yup. Head Code Monkey[tm] favors lots of manual labor like that.


Can't you find another tree to work then? Sheesh.

Using unbound forms, so bypassing all mechanisms that make Access so
slow and large; well, I started a company of my own for such reasoning.
eh, it's the same deal. the difference is that before you mentioned the
.ControlType property, I never new it existed. :)
Welcome to Property country.
The reason I'm using multiple IFs is that i'm doing some manipulation
of some labels to let my users feel all nice about themselves >:) ("YOU
HAVE ENTERED A NEW RECORD!")
I'll take that. Humans (counting me as one :-) ) don't have to
understand everything.
You can do whatever you want to separate labels inside the Case acLabel.
I guess you will do that.
my code is local to the form. i got a module (which i should turn into
a class some time in the future) but only things that more than 1 form
uses go there (like my emtpyRowSources( byref tmpForm as Form) )
Does it have to become a Class? Classes form objects you can create; to
have just a function repository does not require class status. It would
even hamper certain simple things. (Don't show this message to the Head
Monkey then.)
By the way, what's wrong with passing forms and objects by reference?
Strong-typed question. In itself there is nothing wrong with passing
forms by reference. It is the only possible way, accidentally.
It *would* be possible to pass an object by 'value' (whatever that may
mean) but man, that is memory intensive.
Head Code Monkey insists its the wrong way to do things and that's it's
memory intensive. I'm like "Chill man, I'm passing a pointer, not the
whole object"
Exactly. Just four bytes. Intensive to his memory, maybe.
Boss loves unbound forms. He insists we use unbound forms. if he let me
use bound forms, this project would be over 2 months ago. that's why i
had to learn how to manipulate a form by hand.
The other thing you said about control order, what is that supposed to
bring? Because that part of the question I haven't addressed yet, and I
think I can contribute.
As for emotional, heh, I'm Greek ^_^


<VBG> I am musician, I play folk music from the eastern Europe region. I
can't understand all those languages but I speak their music perfectly.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #7

P: n/a
<Pr**********@gmail.com> wrote
Boss loves unbound forms. He insists
we use unbound forms. if he let me use
bound forms, this project would be over
2 months ago.
That'd be OK if he were paying for the work... but if I found a contractor
or vendor with that attitude, I'd ask for my money back, and then fire them.
that's why i had to learn how to manipu-
late a form by hand. As for emotional, heh,
I'm Greek ^_^


No particular fun in that, but it does give you some "job security" as
everything will take longer to complete than using bound forms.

Larry Linson
Microsoft Access MVP
Nov 13 '05 #8

P: n/a
> Can't you find another tree to work then? Sheesh.
I'm trying man, i'm trying. By the way, i'm an EU citizen. so, you
know, i can work in holland :) *hint*hint*
Welcome to Property country. I'm here to stay :)
Does it have to become a Class? Classes form objects you can create; to have just a function repository does not require class status. It would even hamper certain simple things. (Don't show this message to the Head Monkey then.) I need to read more on Access Classes and how the differ from VBA
classes
Strong-typed question. In itself there is nothing wrong with passing
forms by reference. It is the only possible way, accidentally.
It *would* be possible to pass an object by 'value' (whatever that may mean) but man, that is memory intensive. What I was really asking was, does access have a problem with its
memory manager? is it dangerous passing pointers in access? are there
any bugs in the way access handles pointers (like pointers becomming
corrupt after a while)? any limitations?

Head Code Monkey insists that the way to go is to pass the name of the
object you want to refer to, and he says so with a passion, so that
makes me wonder, if access is fucking up.

The other thing you said about control order, what is that supposed to bring? Because that part of the question I haven't addressed yet, and I think I can contribute.

i was trying to associate the controls in the forms with the fields
in the database. I had no clue about the Field.Colection(Control.Name)=
Control.Value trick. thought i should have thought about it, because i
was Clueless[tm] and the "Access 2002" and "VBA Developer" books I
ordered from amazon have not arrived yet (grrr >:( ).
so, instead of depending on the name of the controls and the name of
the fields to do the mapping/association, i was using the ordering of
the controls, hopeing that both .Fields and .Controls would be ordered
the same way, internaly. The problem was that they didn't. What
intrigued me though, was the fact that the order of the items inside
the collection was the same, each time i opened the form. That got me
thinking that the collection gets preserved in memory or the .adp file,
somewhere. so, theoritically, it should have an index stored in the
file, which i could mess with, and order the Controls in the same way
the fields in my database were ordered. it was the lame thing to do.
George Marselis

Nov 13 '05 #9

P: n/a
George Marselis wrote:
I'm trying man, i'm trying. By the way, i'm an EU citizen. so, you
know, i can work in holland :) *hint*hint*
If the work ever grows over my head, you'll be invited :-)
I need to read more on Access Classes and how the differ from VBA
classes
%-| VBA is the Basic dialect in Access, I can't see what you're saying here.
What I was really asking was, does access have a problem with its
memory manager?
Yes. Setting a database object variable but not setting it to Nothing
when you're done is known to produce a memory leak quite reliably.

Of course you cannot do anything about this but programming correctly :-)
is it dangerous passing pointers in access?
You don't see it. It is impossible, as opposite to languages as C, to
change the pointer. I mean, you cannot assign it a memory address, only
a variable address.
are there
any bugs in the way access handles pointers (like pointers becomming
corrupt after a while)?
The Database is the only one that really ever bugged me.
any limitations?
NTIK
Head Code Monkey insists that the way to go is to pass the name of the
object you want to refer to, and he says so with a passion, so that
makes me wonder, if access is fucking up.
mmm... if you put the name of the object in the call, the interpreter
*will* pass it as pointer. So maybe all you need is a little diplomacy.
i was trying to associate the controls in the forms with the fields
in the database. I had no clue about the Field.Colection(Control.Name)=
Control.Value trick. thought i should have thought about it, because i
was Clueless[tm] and the "Access 2002" and "VBA Developer" books I
ordered from amazon have not arrived yet (grrr >:( ).
So you use A2K2. In case I forgot. I have A97.
so, instead of depending on the name of the controls and the name of
the fields to do the mapping/association, i was using the ordering of
the controls, hopeing that both .Fields and .Controls would be ordered
the same way, internaly. The problem was that they didn't.
It's a safe bet they don't.
intrigued me though, was the fact that the order of the items inside
the collection was the same, each time i opened the form.
Oh yes, controls do have an order. The order in which they get inserted
is a good candidate, I never really investigated.
Controls that can receive focus have a TabOrder property which
indicates, surprise, the order in which they will receive focus when the
user presses the Tab key.
somewhere. so, theoritically, it should have an index stored in the
file, which i could mess with, and order the Controls in the same way
the fields in my database were ordered.


mmm Name resolution is slightly better. You could even put the data
source name in the Tag property of the control, leaving its name free.
Sometimes you have two controls on one field, effectively defying the
name-source link. With bound forms, that's where the Controlsource
property comes in.
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.