473,592 Members | 2,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using ControlSource Property with an expression

675 Contributor
I have a textbox on a continuous form that I want to display a calculated value. I have set the ControlSource Property = [text1] & "~" & [text2].

I would like to have my user be able to correct this value, and I will un-calculate it using VBA code.

According to Access(2000) Help, I may have an expression for a ControlSource, "The control displays data generated by an expression. This data can be changed by the user but isn't saved in the database." This is good, but I can't make it work. Events such as LostFocus, Click, MouseDown, Enter, Exit can be trapped, but nothing can be entered into the textbox. I get an attractive chime sound.

Of course, my actual problem is more complex, but this simple example illustrates it nicely. Table:
1 AAA aaa
2 BBB bbb
3 XXX xxx
Form has 3 textboxes, with ControlSources = text1, text2, and [text1] & "~" & [text2]

Any help here?

OldBirdman
Dec 11 '08 #1
14 10035
ADezii
8,834 Recognized Expert Expert
@OldBirdman
The syntax for changing the Control Source to an Expression for
<some field> on <some form> is:
Expand|Select|Wrap|Line Numbers
  1. Forms!<some form>![<some field>].ControlSource = "=[Text1] & '~' & [Text2]"
P.S. - You can, in fact, have the Control Source 'persist' if you so desire.
Dec 11 '08 #2
missinglinq
3,532 Recognized Expert Specialist
Help is incorrect! The Control Source is the Control Source! It cannot be changed by the user or thru code.

To do what you want and still have it editable, you need to assign the value using the AfterUpdate events of the two textboxes:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Text1_AfterUpdate()
  2.  If Not IsNull(Me.Text2) Then
  3.    Me.Text3 = [Text1] & "~" & [Text2]
  4.  End If
  5. End Sub
  6.  
  7. Private Sub Text2_AfterUpdate()
  8.   If Not IsNull(Me.Text1) Then
  9.    Me.Text3 = [Text1] & "~" & [Text2]
  10.  End If
  11. End Sub
This also allows the control to be saved to the underlying table if need be, and on a Continuous form (as well as Datasheet) it has to be bound to a field in the table if you want it to be tied to a given record. Otherwise, the value of Text3 for one record is the value of Text3 for all records!
Dec 11 '08 #3
ADezii
8,834 Recognized Expert Expert
@missinglinq
Hello Linq, unless I am totally reading this Thread incorrectly, the Control Source can most definately be changed in the manner in which I described and under the OPs condition, namely:
"The control displays data generated by an expression. This data can be changed by the user but isn't saved in the database."
The Expression will also generate unique values for each Record in the Continuous Form.
Dec 11 '08 #4
missinglinq
3,532 Recognized Expert Specialist
That right, the Control Source can be changed by code, as you've indicated, but from the OP I, perhaps mistakenly, thought he was simply talking about assigning another value to it, not actually changing the value.

And despite what Help says, if you have an expression set as a Control Source, the user cannot edit the control by going into the filed and entering data.

Linq ;0)>
Dec 11 '08 #5
FishVal
2,653 Recognized Expert Specialist
Fathers,

I have a feeling that there is no robust method to do it on continuous form.
Is it worth all efforts at all?

Regards,
Fish.
Dec 11 '08 #6
missinglinq
3,532 Recognized Expert Specialist
As I said in my original post, it has to be bound in order to work on a Contnuous form, which means that the OP would be storing redundant information. While valid arguments can be made at times for storing calculated values, doing so for what appears to be display purposes only is not one of them.

Linq ;0)>
Dec 11 '08 #7
FishVal
2,653 Recognized Expert Specialist
@missinglinq
Amen.

Of course, my actual problem is more complex, but this simple example illustrates it nicely. Table:
1 AAA aaa
2 BBB bbb
3 XXX xxx
Form has 3 textboxes, with ControlSources = text1, text2, and [text1] & "~" & [text2]
Could you anyway tell us your actual problem. It could be well no perfect solution here.

Regards,
Fish
Dec 11 '08 #8
OldBirdman
675 Contributor
Thank you for all your attention to this.

The user sees text3, which contains a calculated value. Text1 and text2 may have .visible=false. I presented a very simple table, but text1 might be LastName and text2 might be FirstName. Then text3.ControlSo urce = text1 & ", " & text2. User enters "Travis James" in text3 and the BeforeUpdate event would assign text1="James" and text2="Travis". User enters "Travis, James" and text1="Travis" and text2="James".

Post #2 - is correct, the ControlSource can be set with VBA code with the syntax shown. This misses this point. The formula can be done in design view, no code necessary. I'm not sure what 'persist' does.

Post #3 - Sorry, but this is incorrect. ControlSource can be changed thru code. The code presented does not do what I asked, which was "I would like to have my user be able to correct this value", which is the calculated field text3. Also, Access is correct with continuous forms, and each record has its own correctly calculated value in text3.

Post #4 - This makes the same observation that I do in my Post#3 comment above.

Post #5 - Again, I want a field to display a calculated value, and I want the user to be able to enter a value into that field. I will then parse the entry, and assign new values to text1 and text2.

On SingleForm view, this can be done using an unbound textbox. Text3 would be updated when the form's OnCurrent event occurred, and text1 and text2 would be updated when text3.AfterUpda te occurred. For continuous forms, this does not work, as all occurrences of text3 would contain the same value.

I notice that for Access 2003 VBA "http://msdn.microsoft. com/en-us/library/aa224120(office .11).aspx" has the same statement that data can be changed but is not saved.

Post #6 - I thought it was worth it, or I wouldn't have asked.

Post #7 - If I wanted to display names in FirstName <space> LastName order, but ORDER BY LastName, FirstName I would need a display field. If my data came from another source (Internet, text document, etc.) and was entered by Copy - Paste, the display/entry field would be useful (but not required).

Post #8 - Perfect solution? The only solution presented is to create a display field in the table, which is the largest field in the table. Am I to believe that Access Help is wrong, "msdn.microsoft .com/en-us/library" for Access 2003 VBA is wrong, or that a bug has existed for about a decade?

Actual problem is for a kiosk in a movie rental store, and the updating of the database will be done by the store clerks. Customer scans alphabetic list of titles, selects one, and gets Store Location, MPAA Rating, etc. Clerk must deal with complex titles. I thought I could use a subform, continuous forms, to show the first letter and the name as it should appear. Clerk could add as many alternate names as desired, probably cut/paste from original name but some movies have multiple titles) and I would parse it, capitalize it, and decide display letter(L~). Clerk could override.

Movie #1 - 3 Display Names - Cut/Paste from original name
N~ National Geographic: Inside American Power: The White House
I~ Inside American Power: The White House
W~ The White House

Movie #2 - 4 Display Names - Cut/Paste from original name
N~ National Geographic: Beyond the Movie: The New World: Nightmare in Jamestown
B~ Beyond the Movie: The New World: Nightmare in Jamestown
N~ The New World: Nightmare in Jamestown
N~ Nightmare in Jamestown

Movie #3 - 1 Display Name - Remove leading article(The)
F~ The Fight for the White House

Movie #4 - 2 Names - Entered separately
S~ Street King
K~ King Rikki

Movie #5 - 2 Names - Entered separately, one with leading article(The)
S~ Serenity
F~ The Firefly Movie

Movie #6 - Simple Name - Remove leading article(The)
P~ The Patriot

Store patron selects "S" on touchscreen and gets:
"Serenity"
"Street King"
On touch screen, Customer selects from this list

OK, so that is the actual problem. I didn't think you all wanted to have to wade thru all this, as solving my simple example would solve the problem. For my personal use, I get the movie titles from the internet, paste into a textbox, and parse. For movies with multiple names, I use continuous forms so I can see all the names at a glance (usually <4).
Dec 11 '08 #9
FishVal
2,653 Recognized Expert Specialist
Hello, O~ Old:Bird:Man. ;)

Is that
National Geographic: Inside American Power: The White House
text entered by user or it is calculated one?

If so, then the problem is quite opposite to that you've initially asked.
The text as it entered should be considered as primary data source.
Master letter could be determined via simple logic and optionally stored if user is supposed to have final decision on that.

But ... hmm ...

From what you've posted I've got a feeling that your table structure is not optimal.
Would you like to discuss it?

Regards,
Fish.
Dec 11 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
20295
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()', this.pinginterval); - but is there no way to do this without using the literal ObjectName? If I write 'this.methodName()' I get "Line 1 Char 1: Object doesn't support this property or method." in IE, and nothing happens in Firebird.
3
4199
by: Shelli Carol | last post by:
Good day, I have: 1) A table with numbered fields (1, 2, 3, etc.) 2) A form text box, whose ControlSource property contains an expression. This expression returns a number. If I just put a number in the ControlSource property, the text box
6
2134
by: CFW | last post by:
References in Access and .mdb files have always been painful for me - just when I thought I was OK in an .mdb, I have a .adp I'm working on and I need to use Set db as CurrentDb - Constant "object variable or with block variable not set" error almost killed me and VB Help says "If you want to use the CurrentDb method in an Access project (.adp) you must set a permanent reference to the DAO 3.6 Object library in the Microsoft Visual Basic...
9
3061
by: Colin McGuire | last post by:
Hi, I have an report in Microsoft Access and it displays everything in the table. One column called "DECISION" in the table has either 1,2, or 3 in it. On my report it displays 1, 2, or 3. I want to appear in the report is Yes, No, or Maybe. What do I need to do to change what appears in the report/what term do I need to search out in Google? Thank you Colin
0
1259
by: Paul T. RONG | last post by:
Hello there, there is a text box txt0, its controlsource is =( & ", " & ) it works in one mdb, but not in another. Where is the problem? please help. Paul
2
2005
by: Ian Hinson | last post by:
Hi, In an MDB report I was able to obtain an Orders total in a Group Footer by setting a control's ControlSource to: =Sum(*) In the Detail section of the report are controls bound to: (1) Description (2) Qty (3) Price, and (4) =*
13
5780
by: ringer | last post by:
Hi, I have a text box on report where I need to have dsum return a total. The records I need the total from are not in the table that is the report's recordsource, and to complicate things further, I need to use a variable that is derived from behind the report in the criteria for the dsum. When I try to see print preview, this version of the statement errors before opening saying "Access cannot find the field 'SavingsPeriodEndDate'...
2
3240
by: DC | last post by:
Hi, I am using a GridView to present data in a DataTable, which I store only in ViewState and when the user hits the "OK" button the rows in the DataTable will be used to execute transactions. I need the ability to insert new rows (which is easily done with DataTable.Rows.Add(newRow) and rebinding) and then present a row with different TemplateFields for those rows (I need multiple rows in this insert state).
2
5427
by: ARC | last post by:
I have a ranking report where I want to sort it different ways depending on the option the user picks. On the On_Open event, I've tried everything I can think of and keep getting error 3071 "This expression is typed incorrectly or is too complex..." Here's the 2 things I've tried, both return the error 3071. If I comment out the code, the report opens normally. The fields SumOfInvTot, Margin, MarginPCT, and Comp all exist both in the...
0
7935
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8236
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8227
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6642
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3851
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1202
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.