如何根据表单更新表中具有相同记录值的字段? [英] how to update a field in a table with a value in the same record based on a form?

查看:77
本文介绍了如何根据表单更新表中具有相同记录值的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这甚至可能吗?


我正在研究一个项目,它基于几个月!

每次我点击一个按钮cmdRunMonthEnd我会喜欢这样做。我将从我不能正确的部分进行解释!


我有一个带有以下字段的表TrnControl:

TrnYear,TrnMonth ,CurrentBalance,1,2到12(月)。


我也有这个名为RunMonthEnd的表单。使用以下未绑定的文本框:

Txt.Year,txtMonth,txtNewMonth,txtCurrentBalance和命令按钮cmdRunMonthEnd。


正如我所说,一切正常我想要的直到点击按钮的程度。当我点击按钮时,如果可能的话,我希望发生以下情况。


单击它时,我希望它更新名为TrnControl的表格。

它应该从名为txtCurrentBalance的表单文本框中获取值,并更新月份之一(1-12)。它应该更新到txtNewMonth中的字段。


因此,如果txtNewMonth为3,那么它必须采用txtCurrentValue并在同一记录中更新名为3的字段,其中TrnYear是和表格上的txtYear一样。


请帮助,对我来说似乎不可能!是吗?


谢谢

Ryno

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

推荐答案

当然有可能。您可以根据txtNewMonth中的内容创建一个动态SQL字符串。


但我要提醒您不要将数据保持在这种非标准化的结构中。
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.


这是可能的,相对简单。你是否想要按照你的解释那样做是有意义的或者是明智的我怀疑,但最终只有你才能知道你为什么要这样做(所以我会把这些事情留给你)。 />

表格中已经有表格中的字段控件(应该是偶然绑定的),包括所有12个编号的月份字段(请不要只使用该字段作为字段名称它真的不是太聪明,可能会给你带来很多问题。),以及一个未绑定的控件[txtNewMonth]。按钮'Click事件背后的代码应根据[txtNewMonth]中的值确定相关控件,并将[txtCurrentBalance]的值复制到其中。在这个阶段保存记录也可能是有意义的。


顺便提一下,在你的问题中包含了这么多有用的细节。
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.


感谢您的回复。你们其中一个人能给我一个我应该用来实现的代码示例。当我创建表格时,我认为只使用月份数字会更容易,因为txtNewMonth只会包含数字值。最初我有Mth1,2,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


这篇关于如何根据表单更新表中具有相同记录值的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆