> You will want the variable to be dimmed at the module level for this to work.
>
[quoted text clipped - 89 lines]
> > > > > would be a lot easier if the table only contained the
> > > > > number.
The lower you dim your variables, the better. The problem with module level
or application level varialbes is that if you inadvertently use the same
variable name at a lower level, you may not be using the variable you think
you are. When you address as variable, VBA looks in the procedure variables
first, then the module varialbes, then the application variables. The only
reason to have a variable outside a procedure is if more than one procedure
needs access to that variable.
If you need to allow any procedure within your module access to a variable,
it needs to be dimmed at the module level. Note that all the code within a
form is in the form's module, so if you dim a variable at the top of the
module, just below the Option statements, it will be visible to all the
procedures in the module.
There are some risks as I have described previously, but if you are careful
about when and how you scope your variables, it should not be a real
problem. The reason I suggested the module level for storing the shop is
that if you confine it to a specific procedure, then the user would have to
enter the shop number every time they enter that procedure (this is not
entirely true, but it does get advanced, so we will ingore it for now - this
disclaimer is for those who will jump in to tell me I'm wrong about that).
I would recommend you dim the variable at the form module level and ask for
the shop code in the form load event. This way, the user will only have to
enter it one time and you can use it any where in the form as long as the
form is open.
> Is it a problem to dim the variable at module level - I thought I read
> somewhere that this is not a good idea as it might cause problems in some
[quoted text clipped - 95 lines]
> > > > > > would be a lot easier if the table only contained the
> > > > > > number.
PeterW - 19 Nov 2006 14:08 GMT
Thank you very much for your help - that all makes sense to me now.
> The lower you dim your variables, the better. The problem with module level
> or application level varialbes is that if you inadvertently use the same
[quoted text clipped - 122 lines]
> > > > > > > would be a lot easier if the table only contained the
> > > > > > > number.