简体   繁体   English

插入问题(access / vb)

[英]Issue with insert (access/vb)

I've been already trying to solve this problem for two days, and i'm going no further with it. 我已经尝试解决此问题已有两天了,对此我不再赘述。

I have two tables in my access application: one of them is called tabDerroga , where some documents' data are saved (mainly its protocol number, or "Protocolo"). 我的访问应用程序中有两个表:其中一个表名为tabDerroga ,其中保存了一些文档的数据(主要是其协议号或“ Protocolo”)。 Another one is called tabLog , and it's used to store logs. 另一个名为tabLog ,它用于存储日志。 I also have a query that checks if there are any log related to a Derroga . 我还有一个查询,用于检查是否有与Derroga相关的Derroga If it does, there's no need to work with it anymore. 如果是这样,则不再需要使用它。 But if it doesn't, I need to process it and then I save the log entry detailing what I did. 但是,如果没有,则需要对其进行处理,然后保存日志条目,详细说明我的操作。 The tabLog table has a [Protocolo Derroga] foreign key/field that points to tabDerroga .[Protocolo]. tabLog表具有一个指向tabDerroga 。[Protocolo]的[Protocolo Derroga]外键/字段。 No issue with it at all. 完全没有问题。

While creating the tables and the query, I've extensively tested everything manually , and it works flawlessly. 在创建表和查询时,我已经手动对所有内容进行了广泛的测试,并且可以完美地工作。 If i create any entry in tabLog where the "foreign field" refers to a tabDerroga entry, this entry will be omitted on the query. 如果我在tabLog中创建了任何条目,其中“外部字段”引用了tabDerroga条目,则该条目将在查询中被忽略。

My problem starts when I add a row to tabLog through VBA. 当我通过VBA向tabLog添加一行时,我的问题就开始了。 If I check the table manually after it, I can confirm that it had been added with success. 如果在表之后手动检查表,则可以确认已成功添加该表。 But the query won't see it . 但是查询看不到它

I can run the code hundreds of times, creating hundreds of rows with the same data, but somehow it seems to be "different" or "invisible" to the rest of the database. 我可以运行该代码数百次,使用相同的数据创建数百行,但是在某种程度上,它似乎对数据库的其余部分“不同”或“不可见”。 If I copy any of these rows and paste on a new entry, this manually added will be instantly "visible" to the query, but all the other rows won't. 如果我复制这些行中的任何行并粘贴到新条目上,则手动添加的该行将立即对查询“可见”,而其他所有行则不可见。 And they all have the SAME DATA . 他们都有相同的数据

This is one of the ways I tried to accomplish the task: 这是我尝试完成任务的方法之一:

MyRS.MoveFirst

MyRS.AddNew
    MyRS![Descrição] = "10 dias antes de vencer"
    MyRS![Protocolo derroga] = Protocolo
MyRS.Update

MyRS.Close

This gives me the exactly same results : 这给了我完全相同的结果

DoCmd.RunSQL "INSERT INTO tabLog ([Protocolo derroga],[Descrição]) VALUES ('" & Protocolo & "','10 dias antes de vencer')"

So does this: 这样:

CurrentDb.Execute "INSERT INTO tabLog ([Protocolo derroga],[Descrição]) VALUES ('" & Protocolo & "','10 dias antes de vencer')"

By the way, I've already checked if the problem is related with any sql injection issue by assembling the whole string first. 顺便说一句,我已经通过首先组装整个字符串来检查问题是否与任何sql注入问题有关。 Got the same results. 得到了相同的结果。

What am I missing? 我想念什么? Do I need to "update" anything before the data is ready to be worked with? 在准备使用数据之前,我需要“更新”任何内容吗? If so, why does it appear normally in the table? 如果是这样,为什么它正常显示在表格中?

Any help will be appreciated! 任何帮助将不胜感激!

How dumb I am. 我真笨 I've completely forgotten about the first and only universal rule on dealing with computers: If it doesn't work, reboot everything. 我完全忘记了处理计算机的第一个也是唯一的通用规则:如果不起作用,请重新启动所有程序。

Went back home yesterday, and today everything is working as expected. 昨天回到家,今天一切都按预期进行。 No code change. 无需更改代码。

Thanks @TimLentine, @ JohnnyBones, @MurDeR and @MP24! 感谢@ TimLentine,@ JohnnyBones,@ MurDeR和@ MP24!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM