Howdy,
I'm running Paradox 9 under Windows 7...
I have some code that adds the one record in a table (invoiceReplacedHold.db) to another table (invoicesReplaced.db). These tables have the same structure, and each is keyed on the first field (invNum.)
But, when I fire the code, the Source table (invoiceReplacedHold.db) loses its key...
Here's the code that deletes the key and the line that does the deed is marked:
qVar0 = Query
ANSWER: :MONEY:InvoiceReplacedHold.DB
:MONEY:INVOICES.DB | InvNumber | Num | Replaces | Replaced | Last |
| Check ~S | Check | Check | Check | Check |
:MONEY:INVOICES.DB | First | Adr | Purpose | InvDate | DueDate | DUE |
| Check | Check | Check | Check | Check | Check |
:MONEY:INVOICES.DB | RECEIVED | Balance | Tag | Comment | ReplaceNote |
| Check | Check | Check | Check | Check |
EndQuery
if not executeQBE(qVar0) then errorshow() endif ;/\/\/\/\/\ REMOVES KEY
sourceTbl = ":MONEY:InvoiceReplacedHold.DB"
destTbl = ":MONEY:InvoicesReplaced.db"
if isTable(destTbl) then
if not sourceTbl.add(destTbl) then
errorShow()
endIf
else
msgStop("Error", "Can't find " + destTbl + ".")
endIf
I ran the code and got an "Incompatible Structures" error, looked at the structure of the two tables and saw that the source table was not keyed (though I felt sure it had been.) So I added the key, and saved the "new" structure. Then I ran the code again, only to get the same error.
I checked yet again, and the key that I had just replaced was gone again...
I put a breakpoint in at the top of the code (yes, there is more, but I have posted the lines that remove the key...)
Next, I checked one more time to see that the key was in place, and stepped through the code. After advancing one line, I looked for the key again. I thought it was going to take all night, but I very quickly found that the line that executes the query removes the key from invoiceReplacedHold.db.
Then, with the key gone, the two tables are indeed incompatable, and of course, my attempt to add the record fires the error.
I have no reason to believe that this is relevant, but...
This code had been working fine, until I needed to add a field to each of the tables. I did that, and made certain that the two tables were modified so as to preserve their identical structures. It was only after making that change that this problem started...
I am baffled, and so ask this question:
Why would running the query remove a table's key? And how can I prevent that from happening?
Very sincere thanks for any help,
Lothar