Re: forms and variables help please

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



To refer to a control on the New form where the control name is a variable,
you'd use

Forms![New].Controls(variable)

If Colour is declared as a public variable in a module, you should be able
to refer to it simply as Colour, not as Dates.Colour. The only reason you'd
need to qualify with the module name is if you've got Colour declared as a
public variable in more than one module, which is not a very good practice.

Try simply using

Forms![NEW].Controls(Colour).BackColor = vbRed

Note that most of the square brackets you had are unnecessary (and, in fact,
may be incorrect)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"lee_cufc via AccessMonster.com" <u51333@uwe> wrote in message
news:9514543576382@xxxxxx
hi guys,

wondering if anyone can help with the following?

[Forms]![NEW]![(Dates.Colour)].[BackColor] = [vbRed]

In this code i'm wanting it to go to the form named 'NEW' and change the
back
color of a textbox to red.
The name of the text box is stored in the global variable 'colour', which
is
declared in the module 'dates' (hence the dates.colour part)
On stepping through my code i know that the name of the textbox is being
stored correctly in the variable im just unsure of how to use this code
with
a variable in?

Any thoughts or ideas?
thanks
Lee

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200904/1



.



Relevant Pages

  • Re: Me. vs Me!
    ... syntax may only be used in a class module (which I don't believe ... you can use Me.controlname or Me!controlname to refer ... running behind FormA you can refer to control txtFieldOnA on FormA using ...
    (microsoft.public.access.modulesdaovba)
  • RE: Selecting columns from a query by using a form
    ... refers to a control on the currently active form or report. ... you have code behind a form or a control on the form, you can refer to any ... not what you see in the listbox. ... Fieldname where Fieldname is a text of the name of the column to be ...
    (microsoft.public.access.forms)
  • Re: need to get form property
    ... The Me prefix means that what follows is a property of the form in which the ... refer to anything specific about the form, but rather sets the table for what ... an event for an individual control. ... then the bang operator is needed. ...
    (microsoft.public.access.forms)
  • RE: Why cant I open a report using VB?
    ... you now have no criteria in the query that refers ... is to check that the control that you refer to to populate the variable ... The query used to refer to "Forms!frmDrive!TestID", ... It works when I call the report straight from the database window ...
    (microsoft.public.access.modulesdaovba)
  • Re: dynamically named controls
    ... is it possible to refer to controls dynamically? ... then refer to the control named in mystring? ... You want the control instance itself. ... // do something with the textbox instance referred to by tbx ...
    (microsoft.public.dotnet.framework)