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"). Another one is called tabLog
, and it's used to store logs. I also have a query that checks if there are any log related to a 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]. 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.
My problem starts when I add a row to tabLog
through VBA. 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. 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!