How to Change Value of Active Control

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
Utf
4/9/2010 9:00:01 PM
access.modulesdaovba 1670 articles. 0 followers. Follow

5 Replies
2457 Views

Similar Articles

[PageSpeed] 23

"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
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
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
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
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
Utf
4/17/2010 9:16:01 PM
Reply:

Similar Artilces:

Exchange Active Sync #4
I have a user with a Sprint PalmOne Treo 650. Sprint advertises that this is supported by Exchange 2003 Server Active Sync. Microsoft has documented that Active Sync is included with Exchange 2003 at no additional cost. I have not been able to find documentation on how to install and configure Exchange 2003 Active Sync to support a Sprint PalmOne Treo 650. Can anyone point me to Microsoft or Sprint/PalmOne documentation on how to setup Exchange 2003 Active Sync to support a Treo 650? I work with the American Red Cross, a non-profit organization. I appreciate your help and support. On ...

Excel 2007 Need to permanently change Normal settings for gridlines
I am using Excel 2007 for the first time and find the gridlines delineating the cells are so faint as to be nearly indistinguishable. I can go into the cell formatting and modify the normal style, and it is just the way I want it. But I can't find a way to make Excel remember this and treat it as the new definition of the Normal style. I don't want to have to redefine Normal every time I open a new spreadsheet. Someone please help! Regards Leonard Priestley The changes you describe are changing the Border color and NOT gridlines. Go into Excel Options and cl...

Changing which database Business Portal points to
If I install Business Portal 2.5 (GP) and point it to our Great Plains development server with an old Dynamics database, once we decide to take it live, how do I go back and point it to the live Great Plains server? Is this something that can only be done during the installation? Let me preface my response by saying I only have experience with BP 3.0.... In BP 3.0 several tables are created in the Dynamics database to support the various BP functions. Unless you plan to move or copy those tables you will probably have to reinstall BP 2.5 in order to have them created. Our attempt to cop...

Cannot set menu in MFC ActiveX control
I am dynamically creating a CMenu object and trying to assign it to my ActiveX control. Windows balks and gives me a 1436 error, something to effect that a child window cannot have a menu. It is not a child window, it is the instance of COleControl, the top level window. (I verified this by inspecting m_parentHwnd.) I am trying to assign the menu within the OnCreate event at which time the control has a valid handle, and have tried it before and after the call to the parent OnCreate. Does anyone know the magic words to make this work? Thanks On Mon, 8 Dec 2008 16:22:02 -0500, Duane A. C...

Changing Titles by a formula
From cell A1:A10 I have standard titles that are linked to another sheet. I only need to change the office and date per each title. Is thier a way to do that making the office and date a formula in another cell? example of title ABC Comp, Office 38L Sales as of 6/07/2004 I need to only keep changeing the 38L and date. Any suggestions----Thanks Say Office # is in Column 'C' in cell A1: ="ABC Comp, Office "&C1&" Sales as of "&Today() ----- Heather wrote: ----- From cell A1:A10 I have standard titles that are linked to ...

problem in changing the text of sentences before tables
I am developing a word automation application. In a method of mine, I change the text of some sentences of an opened word file, but the problem is when I change the text of a sentence which located before a table, it will be moved to the first cell of the table. My code is as follow: void myMethod( long startingSentenceNumber, const char *toBeSearched, const char *replacement, bool replace ) { Range currentSentenceRange; Selection sentenceSelection; Sentences sentencesList = m_document.GetSentences(); long sentencesCount = sentencesList.GetCount(); CString replacementCStr(...

reflecting values in a column into a row
I am creating a chart to map a round-robin chess game. If there are 4 players, then all 4 has to play one another. if I have the names John Mike Sally Bill Then I'd like to type them into a columns and write a formula in a row to pick up the names the spreadsheet should then look like this: John Mike Sally Bill John Mike Sally Bill I think it may be achieved with the Indirect() function, but my Excel 2007 help seems broken and I can't figure it out without an example. Thanks. MikeB With names in A2:A5 Enter in B1 =INDIRECT("A"&COLUMN(B1)) Or...

can't change/delete bills and deposits
suddenly one day i realized that when i tried to change a bill, i could click "ok" but nothing would happen. I thought it was because i upgraded to 2004, so i deleted the bills and rescheduled. about 5 of the bills will not delete either. the error message is: "Money could not write to your Money file. The operation could not be performed or another application finished this task before you. Please try again." Now some of the newly scheduled bills will not allow me to change the properties, i click ok but nothing happens when i edit the series. I have repaired ...

Outlook 2007: When i Save a New Rule outlook Change it automatically...
Hi people! I have this problem with Outlook 2007. I have 15 e-mails addresses in my outlook, but i can=B4t create the rules for send all the received mails to each emails folder. Example: I want to create a simple rule that move all the e-mail that i get from "example1@example1.com" to the folder "Inbox/ example1@example1.com". When i create the rule, all works fine, i select the correct e-mail account name, the correct destination folder, etc... but when I hit the SAVE button in rules window, Outlook 2007 changes the account automatically to another one. Not automatically...

Change Row/Column Height & Width
I know I should be able to automatically set a row height to the max necessary by hovering the cursor between the 2 rows I want to adjust and double-clicking, but sometimes this doesn't always work. Why is that that - do I need to adjust a setting? And is there any way to set it so that if text is added or deleted the row height would change automatically so thatthe text fit appropriately? Set the row format to Autofit and cells to Wrap Text Gord Dibben MS Excel MVP On Tue, 19 May 2009 12:14:04 -0700, DaveL <DaveL@discussions.microsoft.com> wrote: >I know I should be ...

Changing Functional Currency #4
Try to change the functional currency to Z-CNY. ERROR = Activity for this currency already exist. Finance made 2 GL transactions. Can we remove the transactions (Tools >> Utilities >> Financial >> Remove History) or (File >> Maintenance >> Clear Data ) then change the functional currency? Which tables should I remove history or clear data. Can someone on the board help us? regards, Once you process a transaction, you are stuck with the functional currency. I have not seen a table fix for this problem on the board. Consider creating a new database an...

need to make a formula that would add a field value to current dat
I have made a form in which I input different values. On of the values is (How Many Days). Now I need to a assign a default value, or expression (not sure which way to go about this) that will take the date value for (Date) and add the value (How Many Days) I figured that the formula should read =sum([Date]+[How Many Days]) But that is not giving me any results, thanx for your help in advance =DateDiff("d", Date(), [How Many Days]) -- Wayne Manchester, England. "J Man" wrote: > I have made a form in which I input different values. On of the values is ...

Change default "SaveAs" to *.msg rather than *.html
Hi!, Using Outlook 03, I regularly need to save emails and prefer to save as *.msg so the attachments are contained within the one file. How can you change the default SaveAs command to Save as Type in a *.msg format (rather than *.html) so the type is already *.msg without having to use the pull down? Thank you Troy Outlook provides no way to change that. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "TroyB" <boeky72@hotmail.com>...

adding date/time picker to inputbox control
Hi all,is there a way to add a date/time picker control to inputbox?...

change column name from letters to numbers?
I'm importing a 3rd party CSV file into Excel and then comparing some of the contents to a printed spec. Each numbered field in the spec corresponds to a column in the work sheet. I'd like to change the column headers from letters to numbers. Is that possible? Tools-->Options, General tab. Check the R1C1 Reference Style. ******************* ~Anne Troy www.OfficeArticles.com www.MyExpertsOnline.com "Jerry" <jerry@nowhere.com> wrote in message news:OoyPef$eFHA.3048@TK2MSFTNGP12.phx.gbl... > I'm importing a 3rd party CSV file into Excel and then comparing ...

column value translation
I'm sorry if this is already here somewhere, but I could't find any references. I need to upload a list of people into our computer system and this list is comprised of their names and the code for the branch where they work. The computer system into which I need to upload this list will not recognize the current branch ID code for those employees, but I do have a list that is basically a comparison of the two different codes. For example branch code 800 on the list equals branch code C001 in the system. I need to get a way in excel to convert all the branch codes that are next...

Changing of range (Address) to (Cell)
Hi people I have encounter a problem with the use of range From a recorded macro, it's listed this way ActiveChart.SetSourceData Source:=Sheets("Trend").Range("A1:M2,A24:M28"), PlotBy:=xlRow And I edit it to this way ActiveChart.SetSourceData Source:=Sheets("Trend").Range("A1:M2," & Cells(StartX, StartY), Cells(LastX, LastY)), PlotBy:=xlRow And obviously VBA compiler won't let me go this easily, it happen to give an "evil-comment" on my source range, May i know how can i solve this Thank You Hi Kaiyang, Try this, assuming the...

domain controller
If I have a more powerful comuter than needed, can I run Exchange 2003 on a Windows 2003 domain controller, which happens to be the first domain controller in the domain? Yes, you can though it's not recommended. "rook" <anonymous@discussions.microsoft.com> wrote in message news:7e6901c4849a$4ff93a60$a401280a@phx.gbl... > If I have a more powerful comuter than needed, can I run > Exchange 2003 on a Windows 2003 domain controller, which > happens to be the first domain controller in the domain? Yes it is extreamely not recommended because your so called &qu...

Net change and percentage of change
Hi, I have a list of parts that have had price increases. One column has the old price the other has the new price. I need to show the difference, whether it is positive or negative and the percentage of the increase or decrease. The difference is not a problem. The problem lies in calculating the percentage. I don't how to do that. Can someone tell me? Thanks, Richard =(B1-A1)/B1 "Richard" wrote: > Hi, > > I have a list of parts that have had price increases. One column has the old > price the other has the new price. I need to show the difference, whethe...

Out of Office not active Entourage 2008 exchange 2007
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Email Client: Exchange Hi, <br><br>I have Entourage 2008 with latest service pack. Exchaneg 2007 sp2. MAC OS X 10.6. Out of Office works for Outlook and OWA. When I open up Entourage on any MAC and go to Tools, the Out Of Office is dimmed/ not active? Any idea? <br><br>Thanks, <br><br>Mike ...

Working with a worksheet that is not the active worksheet
How can I make this code work on my worksheet named February, when it is not the active worksheet? Sub BlankWeeks() ' ' Macro2 Macro ' ' If Range("C184").Value = "" Then Rows("184:228").Hidden = True End If If Range("C184").Value <> "" Then Rows("184:228").Hidden = False End If If Range("C229").Value = "" Then Rows("229:273").Hidden = True End If If Range("C229").Value <> "" The...

XML Deserialize of empty value
Hello, I'm encountering a strange issue when deserializing a piece of XML. If I have the following XML and try to deserialize it, everything works: <page> <format>Letter</format> <margin>1</margin> </page> If I have the following XML, everything works: <page> <format></format> <margin>1</margin> </page> BUT if instead I have the following XML, the "margin" element is always 0: <page> <format /> <margin>1</margin> </page> Why...

Fill cells with interpolated values
Hi What is the easiest way to fill cells with linear interpolated values ? e.g. i have value 5 in cell A1, and value 15 in cell A6. Cells A2 ... A5 should now be filles with 7, 9, 11, 13. of course, it's not a big deal to write a formula for interpolation, but maybe there is more simple way, (just by some mouse clicks....?) Biff Select the range A1:A6 with your start and stop value in their respective cells, and then do Edit / Fill / Series / Trend / Linear -- Regards Ken....................... Microsoft MVP - Excel Sys Spec - Win XP Pro / XL 97/00/02/...

Changing Average Cost GP 9.0 Error
When we try to change the average cost information for an item per the documentation, (tools >> utilities >> inventory >> change average cost), we get this message. "Use the Inventory Adjust Costs window to change the cost of one or more reciepts. The average cost of an item is recalculated when teh changes are proceses" We would like to change it without using the Inventory Adjust Costs window because there are no recent purchases and receipts of the particular item in question Would anyone have any suggestions? The average cost is the aver...

Search and display a value from a XMLDOCUMENT
Hi I have the following XMLDOCUMENT loaded in memory: <Datos_de_INGC011_CAT_INDICADORECONOMIC> <INGC011_CAT_INDICADORECONOMIC> <COD_INDICADORINTERNO>317</COD_INDICADORINTERNO> <DES_FECHA>2010-06-28T00:00:00-06:00</DES_FECHA> <NUM_VALOR>517.51000000</NUM_VALOR> </INGC011_CAT_INDICADORECONOMIC> </Datos_de_INGC011_CAT_INDICADORECONOMIC> And I need to retreive the value in <NUM_VALOR>, I had tried of many ways, but I can´t do it, Please somebody h...