473,513 Members | 2,375 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 (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 2194
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 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
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 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
7282
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
2226
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
2873
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
4931
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
1565
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
1827
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
3381
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
3562
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
3517
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
4275
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
7175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7391
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,...
0
7542
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...
0
5697
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,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3247
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...
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
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...

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.