473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Field auto-update based on another field value

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 (txtLiabilityCategory) 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 2190
twinnyfo
3,653 Expert Mod 2GB
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 txtLiabilityCategory = "Madeni", and also meets one of the other two criteria you have listed, you want to adjust the value for txtLiabilityCategory 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
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 txtLiabilityCategory 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
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...
3
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...
8
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...
1
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...
1
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...
2
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...
9
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...
8
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...
3
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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...

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.