473,672 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Field auto-update based on another field value

14 New Member
Hi there,

I'm trying to automatically update a field in a table based on what has been inserted in another field. I have been successful in one table but not in another although I have been using the same code, and the same way. Here is the piece of code which is not working;
Expand|Select|Wrap|Line Numbers
  1. Dim rsLiability As DAO.Recordset
  2.     Dim strSql As String
  3.  
  4.     strSql = "SELECT txtLiabilityCategory, txtLiabilityName FROM tblLiability;"
  5.     Set rsLiability = DBEngine(0)(0).OpenRecordset(strSql, dbOpenDynaset)
  6.  
  7.     Do While Not rsLiability.EOF
  8.      If rsLiability!txtLiabilityName = "Dhima/Mkopo wa Muda Mrefu(Zaidi ya mwaka mmoja)" And rsLiability!txtLiabilityCategory = "Madeni" Then
  9.         rsLiability.Edit
  10.         rsLiability!txtLiabilityCategory = "Non-current"
  11.         rsLiability.Update
  12.      ElseIf rsLiability!txtLiabilityName = "Dhima/Mkopo wa Muda Mfupi(Chini ya mwaka mmoja)" And rsLiability!txtLiabilityCategory = "Madeni" Then
  13.         rsLiability.Edit
  14.         rsLiability!txtLiabilityCategory = "Current"
  15.         rsLiability.Update
  16.      End If
  17.         rsLiability.MoveNext
  18.     Loop
  19.  
  20.     'Closing and resetting the recordset
  21.     rsLiability.Close
  22.     Set rsLiability = Nothing
I have attached the code to the OnClose event of the input form. The field that need to be updated (txtLiabilityCa tegory) is defaulted to 'Madeni'.
Any idea of why it doesn't work or other way around to do it better?
Jul 27 '14 #1
2 2212
twinnyfo
3,653 Recognized Expert Moderator Specialist
So, if I read your code correctly, every time you close your form, you want to cycle through all records in the table in question, then, if txtLiabilityCat egory = "Madeni", and also meets one of the other two criteria you have listed, you want to adjust the value for txtLiabilityCat egory accordingly? I just restate, so that I am clear in knowing what you want to do.

One trouble area that I see in is lines 8 and 12. Although, "Dhima/Mkopo wa Muda Mrefu(Zaidi ya mwaka mmoja)" is, in fact, a text string, inclusion of a reserved symbol like "/" causes problems when using that string for evaluations. You may want to use a dash, which is still not a perfect solution, or another way of identifying this record. You could use:

Expand|Select|Wrap|Line Numbers
  1. If Mid(rsLiability!txtLiabilityName, 27, 5)  = "Zaidi" _
  2.     And rsLiability!txtLiabilityCategory = "Madeni" Then
  3. ...
  4. If Mid(rsLiability!txtLiabilityName, 27, 5)  = "Chini" _
  5.     And rsLiability!txtLiabilityCategory = "Madeni" Then
But this may cause problems if you every change those values in your text field.

However, this might be a place to start....
Jul 28 '14 #2
MfanyaKitu
14 New Member
What I want is to populate a hidden field based on a combo box option selected by the user, and I have decided to use the OnClose event of the form. So from your first paragraph question, the answer is yes, that's what I thought would be the way out to accomplish the task.

Unfortunately your advice and code has failed to solve the issue, the txtLiabilityCat egory default value-Madeni- remains unchanged regardless of the option chosen.
Jul 28 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
7291
by: jochen scheire | last post by:
Is there a way I can calculate a field in a form based on another field in the same form. When clicking submit, both values should be posted to the next page. I want to be able to type in a value in one field, and automatically in a second field the value*1,36 should appear.
3
2239
by: skinnybloke | last post by:
Hi - I have the following VB function within MS Access which is called via a query. How do I modify this code so that it will only do the replacement based upon the value of another field on the same record. i.e. it will replace "10091200" with "Womens Clothing" only if the field TEST = "YES"
8
2882
by: 14erclimb | last post by:
Hi, what a great resource this forum is! Hopefully you all can help: I have one field called "OPERATION_NO" another called "WORK_CENTER_NO" and another field called "OPER_STATUS_CODE" I'm using "2110" as the criteria for "WORK_CENTER_NO" What I want is to create another field called "CURRENT_WC" where the value will be the "WORK_CENTER_NO" of the highest "OPERATION_NO" that has an "OPER_STATUS_CODE" of "Closed" I'm going crazy trying...
1
4950
by: nithingujjar | last post by:
Hi, I need to to hide a field"addr_state1" based on a value in the drop down list field called "addr_country".i.e.,if addr_country.value=="in" then hide addr_state1 else , and if the value in the selection changes to something else then show the field addr_state1. Also the addr_state1 should be hidden when the page loads with value "IN", and if the page loads some other value than show the addr_state1 field. Code used for this is :(I have to...
1
1582
by: gedwards | last post by:
I'm trying to create a database to keep track of donations. I have 2 tables. One that has all the person information plus the Amt. pledge, Amt. Paid, and Amt. Remaining. The other table had Date and Pledge Amt. Paid. What I'm trying to do is get the sum from Pledge Amt. Paid in table 2, to populate the Amt. Paid field in table 1. I've tried using the expresson builder under the Amt. Paid field, I've done =Sum(Table2!) and that returns...
2
1832
by: DeanL | last post by:
Hi guys, I'm using a subform to display a list of values from a single table. The form is showing the values in "continuous forms" view and there will only ever be two different values for the form. The form show 2 fields, 1 is a number and the second is a calculated field that says either "Valid" or "Invalid" based on the first fields contents. What I need to do is if the value is Invalid then I'd either like the text or the actual...
9
3390
by: clloyd | last post by:
I thought I posted this earlier but must have not completed it. I have a field Status that I have a default value on of Open when a user adds a new record. This is an older form and I just added the default to avoid people leaving it blank. This same field also populates another field based on the selection they make in the field Status. My problem now is if the user keeps the default (does not change it to another selection or does not...
8
3574
by: mjvm | last post by:
Hi, I have had a similar question answered but don't understand code sufficiently to adapt it myself. Can someone please help and write the code I need? I have a date field called Received, and when a date is entered in this field, I want another field called Action to be compulsory or required. The Action field is a drop down box (Combo?). I am assuming it is an AferUpdate event, but I may be wrong. Thanks so much for the help I get...
3
3526
by: BobbyD1120 | last post by:
I have created a inventory tracking database and I want to show/hide certain fields based on the device category. The deviceCategory field is a lookup field to a table that lists all the different type of devices to include PC, Printer, Network.... I want it so that when you select a certain category device you get the fields related to the device. For example if you get PC I want to show the fields for Model, Service Tag, RAM, .... For...
4
4288
by: nedryerson | last post by:
Hi, I'm trying to get a certain field to appear only when a value from another combobox field is selected. Specifically, when "Sample Rejected" is selected in the field "PcrLabResults," I would like the "ReasonsRejected" field to appear. I've set the visibility option for "ReasonsRejected" to "No" already. I still can't get it to work. Do I need to do anything after entering this code (ie save, click "run," etc), or will it update in the...
0
8508
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
8854
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...
0
8704
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
7484
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
5727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4253
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
4448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2104
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1851
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.