How to Change Value of Active Control

  • Follow


I'm writing a routine to change the value of any Active Control to null.  I 
can get the name of the control using ActiveControl.Name but I can't figure 
out the syntax to change the value of this control.  I've tried assigning it 
to variables but variables aren't working in a:

Forms![variable]![variable] = ""

Help
0
Reply Utf 4/9/2010 9:00:01 PM

"Sondreli" <Sondreli@discussions.microsoft.com> wrote in message 
news:AA05A840-2AFE-4F98-ABE9-5D2DD17AE0B8@microsoft.com...
> I'm writing a routine to change the value of any Active Control to null. 
> I
> can get the name of the control using ActiveControl.Name but I can't 
> figure
> out the syntax to change the value of this control.  I've tried assigning 
> it
> to variables but variables aren't working in a:
>
> Forms![variable]![variable] = ""


ActiveControl -- whether Screen.ActiveControl or the .ActiveControl property 
of a form -- returns a reference to the control itself, so you can just 
assign a value to that reference.  For example,

    Screen.ActiveControl = Null

or (for the active control on the current form):

    Me.ActiveControl = Null


-- 
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

0
Reply Dirk 4/9/2010 9:11:34 PM

Do you mean "null" the same way Access means "null"?  (if so, see Dirk's 
reply)

Regards

Jeff Boyce
Microsoft Access MVP

-- 
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"Sondreli" <Sondreli@discussions.microsoft.com> wrote in message 
news:AA05A840-2AFE-4F98-ABE9-5D2DD17AE0B8@microsoft.com...
> I'm writing a routine to change the value of any Active Control to null. 
> I
> can get the name of the control using ActiveControl.Name but I can't 
> figure
> out the syntax to change the value of this control.  I've tried assigning 
> it
> to variables but variables aren't working in a:
>
> Forms![variable]![variable] = ""
>
> Help 


0
Reply Jeff 4/9/2010 10:14:55 PM

Dirk,

That doesn't work.  here is my code.

Public Function ClearCBOList()
    Dim frmCurrentForm As Form
    Dim frmCurrentControl As Control
    Set frmCurrentForm = Screen.ActiveForm
    Set frmCurrentControl = Screen.ActiveControl
    Screen.ActiveControl = Null
    DoCmd.Requery frmCurrentControl.Name

End Function

It is a public function to clear any Combo box after a selection is made.  
The error I get with this code is that "You can't assign a value with this 
object"  If I use ME it says it is an Invalid use of the Me object.

If I check the value of the variables frmCurrentForm and frmCurrentControl 
it is the name that I would expect.  I just want to clear the VALUE of the 
current control, not the name of the control.

any help would be appreciated.

Sondreli

"Dirk Goldgar" wrote:

> "Sondreli" <Sondreli@discussions.microsoft.com> wrote in message 
> news:AA05A840-2AFE-4F98-ABE9-5D2DD17AE0B8@microsoft.com...
> > I'm writing a routine to change the value of any Active Control to null. 
> > I
> > can get the name of the control using ActiveControl.Name but I can't 
> > figure
> > out the syntax to change the value of this control.  I've tried assigning 
> > it
> > to variables but variables aren't working in a:
> >
> > Forms![variable]![variable] = ""
> 
> 
> ActiveControl -- whether Screen.ActiveControl or the .ActiveControl property 
> of a form -- returns a reference to the control itself, so you can just 
> assign a value to that reference.  For example,
> 
>     Screen.ActiveControl = Null
> 
> or (for the active control on the current form):
> 
>     Me.ActiveControl = Null
> 
> 
> -- 
> Dirk Goldgar, MS Access MVP
> Access tips: www.datagnostics.com/tips.html
> 
> (please reply to the newsgroup)
> 
0
Reply Utf 4/13/2010 7:53:01 PM

"Sondreli" <Sondreli@discussions.microsoft.com> wrote in message 
news:4DCD0DEC-C5CE-43EE-9F63-34342199C474@microsoft.com...
> Dirk,
>
> That doesn't work.  here is my code.
>
> Public Function ClearCBOList()
>    Dim frmCurrentForm As Form
>    Dim frmCurrentControl As Control
>    Set frmCurrentForm = Screen.ActiveForm
>    Set frmCurrentControl = Screen.ActiveControl
>    Screen.ActiveControl = Null
>    DoCmd.Requery frmCurrentControl.Name
>
> End Function
>
> It is a public function to clear any Combo box after a selection is made.
> The error I get with this code is that "You can't assign a value with this
> object"  If I use ME it says it is an Invalid use of the Me object.
>
> If I check the value of the variables frmCurrentForm and frmCurrentControl
> it is the name that I would expect.  I just want to clear the VALUE of the
> current control, not the name of the control.


It works fine for me, even using your code as posted above, which is more 
elaborate than necessary.  What version of Access are you using?  I tested 
with Access 2003.

It may be that you are calling the function under conditions that prevent 
updating the current control.  How exactly, and in what event, are you 
calling the function?

-- 
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

0
Reply Dirk 4/13/2010 8:36:57 PM

Dirk,

I'm using 2007 and I call this procedure that is located in a global module 
from a private procedure in a form.  I had extra code in there just to check 
values.  When looking at a Help screen it indicated "Read Only"?

I can code it in each form but was looking for common routine.

"Dirk Goldgar" wrote:

> "Sondreli" <Sondreli@discussions.microsoft.com> wrote in message 
> news:4DCD0DEC-C5CE-43EE-9F63-34342199C474@microsoft.com...
> > Dirk,
> >
> > That doesn't work.  here is my code.
> >
> > Public Function ClearCBOList()
> >    Dim frmCurrentForm As Form
> >    Dim frmCurrentControl As Control
> >    Set frmCurrentForm = Screen.ActiveForm
> >    Set frmCurrentControl = Screen.ActiveControl
> >    Screen.ActiveControl = Null
> >    DoCmd.Requery frmCurrentControl.Name
> >
> > End Function
> >
> > It is a public function to clear any Combo box after a selection is made.
> > The error I get with this code is that "You can't assign a value with this
> > object"  If I use ME it says it is an Invalid use of the Me object.
> >
> > If I check the value of the variables frmCurrentForm and frmCurrentControl
> > it is the name that I would expect.  I just want to clear the VALUE of the
> > current control, not the name of the control.
> 
> 
> It works fine for me, even using your code as posted above, which is more 
> elaborate than necessary.  What version of Access are you using?  I tested 
> with Access 2003.
> 
> It may be that you are calling the function under conditions that prevent 
> updating the current control.  How exactly, and in what event, are you 
> calling the function?
> 
> -- 
> Dirk Goldgar, MS Access MVP
> Access tips: www.datagnostics.com/tips.html
> 
> (please reply to the newsgroup)
> 
0
Reply Utf 4/17/2010 9:16:01 PM

5 Replies
668 Views

(page loaded in 0.097 seconds)

6/4/2014 12:28:19 AM


Reply: