使用记录集向MSAccess表添加记录(使用For ... Next循环) [英] Adding records to the MSAccess table with recordset (using For...Next loop)

查看:138
本文介绍了使用记录集向MSAccess表添加记录(使用For ... Next循环)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,


此查询与MSAccess-Forms-VBA编码相关,使用记录集将新记录添加到表中。


例如,我有一个名为''Table1''的表,其中包含字段F1,F2,F3,F4。在Form中,我有四个TextBox,命名为txtF1,txtF2,txtF3,txtF4。我有一个名为''Command19'的命令按钮。


我想在''Table1'中插入一条记录。我想使用循环将TextBoxes中的值添加到''Table1'中的Fields。我想循环以便我可以插入更多数据。


这是我编写的代码。任何人都可以在以下命令按钮中帮助代替XXXXXXXXX使用什么代码。

Dear All,

This query is related to MSAccess-Forms-VBA coding to adding new records in to a table using recordset.

For example, I have a table named as ''Table1'' with fields F1, F2, F3, F4. In the Form, I have four TextBoxs named as txtF1, txtF2, txtF3, txtF4. I have a Command button named as ''Command19''.

I would like to insert a record into the ''Table1''. I want to use a loop to add the values from TextBoxes to the Fields in the ''Table1''. I want to loop so that I can insert more data.

Here is the code I had written. Can anyone help what code can be used in the place of ''XXXXXXXXX'' in the following command button.

展开 | 选择 | 换行 | 行号

推荐答案

我想你是从某个地方复制过来的。 Anway,''xxxxxx''表示表中的字段名称:IE是
I guess you copied this from somewhere. Anway, ''xxxxxx'' represents the field name in the table: IE the name of the field in which the value of
展开 | 选择 | Wrap | 行号


另外你似乎没有宣称我是一个变量。您需要将其声明为整数。

Also you don''t seem to have declared I as a variable. You will need to declare it as an integer.

展开 | 选择 | Wrap | 行号


感谢Jerry的回复。


首先,我的帖子中有一个错误。那不是!'XXXXXXXXX''= Me(txtF"& I),我写道!''XXXXXXXXX''= Me(" txtCh"& I)。


对不起,你的猜错了。它没有被复制,可能我在其他一些你可以在那里看到的论坛上问过这个问题。:-)。


其实我正在做一个包含更多字段的项目。为了方便,我将字段名称作为运行号码,例如''F1'',''F2'',......''''F80''和文本框名称为''txtF1'',''txtF2 '',...... '' txtF80'。所以,如果我使用循环,我认为我可以通过减少大量编码轻松添加。


*****!''你的表字段名称''=我(txtCh& I)******

是的,我知道这一点。但问题是如果我直接使用F1,F2,F3 ...... F80,那么我必须写出80个这样的代码。我试图找出摆脱这个的解决方案。


麦卡锡:

感谢您的回复。我也像你说的那样尝试但是徒劳无功。


来自两个人的任何建议吗?


谢谢&此致,

M
Thanks Jerry for your kind reply.

First of all, there is one error in my posting. That is instead of "!''XXXXXXXXX''= Me("txtF" & I)", I wrote !''XXXXXXXXX''= Me("txtCh" & I).

Sorry, your guess is wrong. It is not copied, probably I have asked this question in some other forum which you could have seen over there.:-).

Actually I am working one project which contains more fields. For convienence, I gave the field name as a running number, example ''F1'', ''F2'', ....''F80'' and the textboxes names are as ''txtF1'', ''txtF2'',....''txtF80''. So, if I use a loop I thought I can able to easily add as I mentioned by reducing numerous coding.

*****!''your table field name''= Me("txtCh" & I)******
Yes, I am aware of that. But the problem is if I use straight away F1, F2, F3....F80, then I have to write 80codes like this. I am trying to find out the solution to get rid of this.

To McCarthy:
Thanks for your reply too. I too tried as you said but ends in vain.

Any suggestion from bothplease?

Thanks & Regards,
M


这篇关于使用记录集向MSAccess表添加记录(使用For ... Next循环)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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