473,394 Members | 1,971 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.

how to update a field in a table with a value in the same record based on a form?

Is this even possible?

I'm working on a project and its based on months!
Everytime I click a a button cmdRunMonthEnd I would like it to do the following. I will just explain from the part where I don't get it right!

I have a table TrnControl with the following fields:
TrnYear, TrnMonth, CurrentBalance, 1,2 through to 12 (months).

I also have this form called RunMonthEnd. With the following unbound textboxes:
Txt.Year, txtMonth, txtNewMonth, txtCurrentBalance and a command button cmdRunMonthEnd.

As I said, everything works as I want up to the point where click the button. When I click the button I want the following to happen if it's even possible.

When it is clicked I want it to update the table called TrnControl.
it should take the value from the forms text box called txtCurrentBalance and update one of the month's (1-12). It should update to the field which is in the txtNewMonth.

So if the txtNewMonth is 3, then it must take txtCurrentValue and update the field called 3 in that same record where TrnYear is the same as txtYear on the form.

please help, it seems impossible to me! Is it?

Thanks
Ryno
Feb 24 '12 #1
11 2052
Rabbit
12,516 Expert Mod 8TB
Certainly possible. You could create a dynamic SQL string depending on what's in txtNewMonth.

But I would caution against keeping your data in such an unnormalized structure.
Feb 24 '12 #2
NeoPa
32,556 Expert Mod 16PB
It's possible and relatively straightforward. Whether your wanting to do that as you've explained makes sense or is wise I doubt, but ultimately only you can know why you're wanting it (so I'll leave that side of things to you).

The form already has controls (which should be bound incidentally) for the fields in your table, which include all twelve numbered month fields (Please don't just use the number as a field name. It really isn't too clever and will probably result in many problems for you.), as well as an unbound control [txtNewMonth]. The code behind the button's Click event should determine the relevant control from the value found in [txtNewMonth] and copy the value of [txtCurrentBalance] into it. It may also make sense at this stage to save the record.

Well done for including so much helpful detail in your question by the way.
Feb 24 '12 #3
Thanks for the replies. Could one of you please give me an example of code I should use for this to happen. When I created the table I thought that using just the month number would be easier, as the txtNewMonth will only have the number value in it. Originally I had Mth1,2,3...

But you're the experts.

I would appreciate it if I can have some code example that I could use.

Thanks
Feb 24 '12 #4
NeoPa
32,556 Expert Mod 16PB
I'm afraid not.

You are expected to try it for yourself first. We're not here to do things for you, but to help when you get stuck. You've been given the directions, now you must do what you can and proceed from there. We can help if you get stuck of course.
Feb 24 '12 #5
Haha...that's why I ask the question. I am stuck. I don't even know where to begin. I'm already confused for what to do after you said about I should not only use a number for the months.

Rabbit talks about a dynamic sql...how must I start if I don't know where and how?

I need help desperately.
At least a starting point.
Thanks
Feb 24 '12 #6
Mihail
759 512MB
I understand well ?
You have 12 fields, one for each month ?
If YES then remove this fields immediately. As Rabbit say such an unnormalized structure come with a lot of troubles.
Even if you'll accomplish the task now you will fall soon in more and more troubles.

So replace all this field with only one:
MonthNumber where to store the month number for your balance then rethink your database at all.

This link is very useful (the best I can say) for a beginner.
http://bytes.com/topic/access/insigh...ble-structures

Good luck !
Feb 25 '12 #7
Hi,

I need to have all the months in the record as I need to update the month value on every month end.
The month need to update through the whole year and store the values for the selected month.

If I run month end for the 3rd month, the value must be stored for that month. If its the 4th month, same needs to happen.
I don't understand what you mean to replace all the months and make one month?

Really I need some sort of code to start this off as I really am even more confused.

Please help!!!

I can't post a code and then ask a question for help if I don't even know where to start.

Please help
Feb 25 '12 #8
Mihail
759 512MB
Not make one MONTH.
Make one FIELD where to store the month number.

Are you follow the link I give you ?
Until you will understand the idea for http://bytes.com/topic/access/insigh...ble-structures, is a wasted time for every one that wish to help you.
Sorry for that. It is MY opinion. Not necessary a true one.
Feb 25 '12 #9
Yes if I create a field to store the months. That would then create duplicate values for the trnYear as it is the primary key field.

I kust need a code to update the value of the month field based on the form as described in my first post.
Feb 25 '12 #10
Mihail
759 512MB
:) If you think so... good luck !
Feb 25 '12 #11
NeoPa
32,556 Expert Mod 16PB
Ryno,

No-one's asking you to be coder of the year here. What you post would only be a start. However, if you cannot think of any code after we've spent time trying to explain these basic concepts to you then it seems we're wasting our time. I've already laid out the basic logic of the code for you in post #. This is a site for offering help to coders, not to code for other people for free. If you need it done for you then you need to think about paying someone for their expertise. Here, we offer help to fellow professionals and amateurs. If you're not prepared even to have a crack at it, after the basics have already been provided for you, then I don't see how you can consider yourself one of those.

As for the month fields, you might consider field names of M1, M2, ... M12 and control names on your form of txtM1, txtM2, ... txtM12. This avoids the silly situation where anything is named simply as an integer value.
Feb 26 '12 #12

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

Similar topics

3
by: Sven Seljom | last post by:
Hi all! I want to take the value from one form-field, deduct the VAT and return the value in another form-field. I have made a Public Function for this and attached it to the text-box. Can...
6
by: John Baker | last post by:
HI: I have a situation where I wish to enter a value in an unbound field on a form and then change the same field in each record on the form so that it reflects the value entered. THe form is...
0
by: EKL | last post by:
Hi, I'm making a sort of Customer and Orders database in MS Access 2003. My problem is that I wish to update the table "tblTransaction" based on changes made in the table "tblOrderDetails"....
1
by: RC | last post by:
I have an Access 2002 database with many tables and forms (but just to keep things simple, let's say the DB has one Table "Table1" and one Form "Form1"). I have managed to cobble together so much...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
5
by: sensreview | last post by:
Hello, I need help in selecting a value from combo list thru one lookup table and update different table on MS access form. For eg; I have a lookup table of usernames, I need to use this...
15
by: sara | last post by:
I have a Memo field in a table to hold notes from a conversation a social worker has had with a client (this is for a non-profit). If the user needs to update the memo field, I need to find the...
4
by: prosad | last post by:
hello, Just solved a problem using Javascript onclick, can click on any cell in a dynamic table and it will pass the innerText object value to my form text field. parts of code given below: ...
5
by: Ferasse | last post by:
Hi, I'm an occasional Ms-Access developer, so there is still a lot of stuff that I don't get... Right now, I'm working on a database that stores contractual information. One of the form that...
11
by: prashantdixit | last post by:
Hi, I am developing a stock control software. Iam stuck somewhere. I have a form "Add new stock" consisting of combobox, text boxes etc. which is used to add records in a table. I have another...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...
0
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
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
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
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.