查看表和开放表单的VBA代码 [英] VBA code to look in table and open form

查看:87
本文介绍了查看表和开放表单的VBA代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我还有另外一个问题。我有一个表格A,其中我输入一个数字#,这个数字存储在表格1中。在同一表格A中,我想添加一个按钮。当我点击这个按钮时,我希望它在表2中查看#I输入的数字是否已经存在。如果不存在,我希望打开表格B,并且在与该字段关联的字段中已经存在数字#,所以我只需填写其余部分。但是,如果它已经在表2中(因此它已经在表格B中),我希望它打开表格B并显示之前输入的所有字段,包括数字#。


有人知道我需要在Private Sub Button_Click()中输入什么VBA代码吗?


这就是我现在所拥有的,但它不起作用:

Hi everyone,

I have another question for you all. I have a form A in which I enter a number # and this number is stored in a table 1. In this same form A, I want to add a button. When I click this button I want it to look in a table 2 to see if the number # I entered is already there. If it is not there, I want form B to open and have the number # already in the field associated to it so I only have to fill in the rest. However, if it is already in the table 2(so it is already in the form B), I want it to open the form B and show all the fields that were previously entered including the number #.

Does someone know what VBA code I would need to enter in the Private Sub Button_Click()?

This is what I have now, but it does not work :

展开 | 选择 | Wrap | 行号

推荐答案

这将有助于您的问题匹配代码。一组与具有不同名称的代码相关联的名称的问题只会使生活变得更复杂。


一般来说,当你遇到这样的问题时,我会考虑打开新表单(问题中的表单B),并使用表单的.Recordset尝试导航到指定的记录。如果失败,则只需设置相关控件的.DefaultValue属性以匹配从旧表单中选择的数字(问题中的表单A)。如果你愿意,你也可以在此时将记录集移动到New Record位置。
It would help for your question to match the code. A question with one set of names associated with code with a different set of names just makes life more complicated.

Generally, when you have an issue like this to deal with, I would consider opening the new form (Form B in your question) and, using the .Recordset of the form, attempt to navigate to the specified record. If that fails then simply set the .DefaultValue property of the relevant control to match the number selected from your old form (Form A in the question). If you prefer, you can also move the recordset to the New Record position at this point too.


我试图简化它而没有所有的名字和东西,但是如果它没有帮助,数字#相当于NoRecom(在某些形式和表中称为NoRecomPaiem)。表A是TblFacture,表B是TblRecomPaiement。对于表单,表单A是FrmFacture,表单B是FrmRecomPaiement。
I tried to simplify it without all the names and stuff, but if it didn''t help, the number # is equivalent to NoRecom (it is called NoRecomPaiem in some forms and tables). The table A is TblFacture and table B is TblRecomPaiement. For the forms, form A is FrmFacture and form B is FrmRecomPaiement.


这对David有一定意义(所以我理解你来自哪里)。它虽然没有这样做。这使得它变得更难。更容易的是能够轻松引用并匹配其中一个。这次没有坏处,但最好记住以后的问题:-)


你的上一篇文章没有评论你是否按照我的指示设法让它工作。我们有兴趣听听它是否有,或者如果您需要进一步的帮助。
That makes a certain sense David (so I understand where you''re coming from). It simply doesn''t work that way though. It makes it harder instead. Easier is to be able to reference across easily and match one to the other. No harm this time, but probably best to remember for future questions :-)

Your last post didn''t comment on whether you had managed to get it to work following my instructions. We are interested to hear if it did, or alternatively if you need further assistance.


这篇关于查看表和开放表单的VBA代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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