PC Review


Reply
Thread Tools Rate Thread

How to Change Value of Active Control

 
 
Sondreli
Guest
Posts: n/a
 
      9th Apr 2010
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
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      9th Apr 2010
"Sondreli" <(E-Mail Removed)> wrote in message
news:AA05A840-2AFE-4F98-ABE9-(E-Mail Removed)...
> 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)

 
Reply With Quote
 
Jeff Boyce
Guest
Posts: n/a
 
      9th Apr 2010
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" <(E-Mail Removed)> wrote in message
news:AA05A840-2AFE-4F98-ABE9-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Sondreli
Guest
Posts: n/a
 
      13th Apr 2010
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" <(E-Mail Removed)> wrote in message
> news:AA05A840-2AFE-4F98-ABE9-(E-Mail Removed)...
> > 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)
>

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      13th Apr 2010
"Sondreli" <(E-Mail Removed)> wrote in message
news:4DCD0DEC-C5CE-43EE-9F63-(E-Mail Removed)...
> 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)

 
Reply With Quote
 
Sondreli
Guest
Posts: n/a
 
      17th Apr 2010
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" <(E-Mail Removed)> wrote in message
> news:4DCD0DEC-C5CE-43EE-9F63-(E-Mail Removed)...
> > 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)
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form active control change event Jim Franklin Microsoft Access Forms 2 19th Sep 2008 11:53 PM
Change Value Active X control =?Utf-8?B?cGhpbGlwcGU=?= Microsoft Excel Programming 3 1st Jun 2006 01:50 PM
how to get inside Active X control the control ID assigned by userat dialog template =?Utf-8?B?eXR2?= Microsoft VC .NET 0 28th May 2004 01:41 AM
Windows.Form: Event on active control change Volker Jobst Microsoft VB .NET 4 4th May 2004 07:52 AM
Change active tab in ASP.net tabstrip control Do Microsoft ASP .NET 0 19th Oct 2003 07:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:14 AM.