Dim VS UnTexbox

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

Which is better to store temporary values? Dim or an Unbound Textbox.
Is one faster? Is one more stable? Can you have several Dims? How
many Dims is too many? Any downsides to one or the other?
Any info appreciated.
Thanks
DS
 
Unbound text boxes would be inapproprate for storing variables. It would be
slower.
All variables should be Dimmed
It is important that you understand varialbe "Scoping", that is what the
visibility of a variable is. Start by looking in VBA Help for the Dim
statment.
 
DS said:
Which is better to store temporary values? Dim or an Unbound Textbox.
Is one faster? Is one more stable? Can you have several Dims? How
many Dims is too many? Any downsides to one or the other?


VBA variables are defintely more efficient. Because any
unhandled error reset your project (clears all variables),
an unbound text box is more stable.

For all practical purposes, the number of Dim statements in
a procedure (or module) is unlimited. The number of
controls on a form or report is limited to a total of 754.
 
Marshall said:
DS wrote:





VBA variables are defintely more efficient. Because any
unhandled error reset your project (clears all variables),
an unbound text box is more stable.

For all practical purposes, the number of Dim statements in
a procedure (or module) is unlimited. The number of
controls on a form or report is limited to a total of 754.
So They both have their pluses. I like the Textbox for stability, but
wouldn't using Dim be faster and also use less resources in Access than
Unbound textboxes. Also won't a form load faster without Unbound
Textboxes. One other question. If I open a form, how can I pass values
along to the new form with Dim. or do the values stay in Dim until they
are overwritten or cleared? If so how do you clear Dim?
Thanks
DS
 
You get your stability by using good error handling procedures. You can learn
about that in VBA Help under On Error.

A Dim statement only establishes the name and type of the varialbe. It
presists as long as it is in scope. You assign a value to it in VBA. It
retains that value until it goes out of scope or you change the value. You
don't really "Clear" a varialbe. It will always have some value as long as
it is in Scope. The default value of a variable depends on it's type. If
you need different forms to share the same variable, it has to be declared
(Dimmed) as Public in a standard module. There are also other techniques for
passsing values between forms, but that is beyond the scope of this
discussion.
 
DS said:
So They both have their pluses. I like the Textbox for stability, but
wouldn't using Dim be faster and also use less resources in Access than
Unbound textboxes. Also won't a form load faster without Unbound
Textboxes. One other question. If I open a form, how can I pass values
along to the new form with Dim. or do the values stay in Dim until they
are overwritten or cleared? If so how do you clear Dim?


VBA variables are naturally faster and use less resources,
but, in practice, you will probably never notice the
difference. As Klatuu said, scope is very important. There
should be no need to use a text box instead of a local
variable. The question only makes sense when comparing a
variable declared as Public vs a text box on either the
current form or an always open form.

You place values in either a variable or a form control by
using a VBA assignment statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top