1 Question and 1 Suggestion
Question: Can you outline the how the tables are built -- Field Name, Field Type, Key, Foreign Key ... that kind of thing.
Suggestion: It sounds like you do not have an error checking routine wrapped around your inserts that might go a long way in helping trouble shoot the when it stops and thus help find out the why. If you do and this has not helped then as part of the Insert (after inserting) you should query the database and make sure the value is there. Throw and error if you do not find it. Again finding out exactly when this happens may go a long way into figuring out why it happens.
MyForms
ID
FormName
FormDesc
MyControls
ID
ControlName
ControlDesc
FormID
FormDesc (this is superfluous but added for testing)
MyLanguage
ID
ControlID
Language (2 digit language identifier)
LanguageText
Field names and relationships should be obvious.
As you point out I don't have any error checking routine but I have 'stepped' through the entire function when it works and when it doesn't work. For form insertions I have the following
strSQL = "INSERT INTO FormNames ([FormName],[FormDesc]) "
strSQL = strSQL & "VALUES ('" & frm & "', '" & Forms(frm).Caption & "');"
Set db = CurrentDb
db.Execute strSQL
newRowFormNames = db.OpenRecordset("SELECT @@IDENTITY")(0)
Response = acDataErrAdded
Set db = Nothing
and for controls I have
strSQL = "INSERT INTO ControlNames ([ControlName],[ControlDesc],[FormID],[FormName]) "
strSQL = strSQL & "VALUES ('" & ctl.Name & "', '" & ctl.Caption & "', '" & newRowFormNames & "', '" & frm & "');"
Set db = CurrentDb
db.Execute strSQL
Response = acDataErrAdded
newRowControlNames = db.OpenRecordset("SELECT @@IDENTITY")(0)
Set db = Nothing
For both I check to see if record is there already and if it is I don't try and add it again.
For both inserts the response (= acDataErrAdded) always= 2 whether the insert works or not.
********
Edit 1
********
Just tested with an on error clause and nothing gets trapped.
********
Edit 2
********
OK it appears I wasn't trapping some errors!
I have now changed
db.Execute strSQL
to
db.Execute strSQL, dbFailOnError
and am trapping the the reason why records aren't being added to MyControls and it is weirder than a weird thing!
I'm getting
Error 3201 (You cannot add or change a record because a related record is required in table 'Field Symptom'.)
There is NO relationship between MyControl and Field Symptom and even if there was how come the it fails in the following fashion...
I start off with no records on MyForms, MyControl and MyLanguages. At this stage the database is repaired and compacted.
I run the function and the right records get added to all 3 files.
I delete the records from MyForms. I have cascaded deletes set so the records are deleted from the other 2 tables as well. I run the function and the records get added to the 3 tables as before. All hunky dory. The only difference is that the ID of the 3 files starts at the next number in sequence after the records were deleted. The SAME records are getting added to each table. I then delete all records from MyForms (records are deleted from other 2 tables). I run the function again and it falls over with the above error. Had I not trapped the error then the MyForms table gets updated, MyControl doesn't (due to above error) and MyLanguages doesn't either as there is now a VALID error in that there is no related record on MyControl .
If I deleted records on MyForms and compact and repair database all works again.
A compact and repair at any other time doesn't solve anything.
Any ideas?
********
Edit 3
********
OK it looks like Field Symptoms and MyControls ARE related according to the database documenter and the field they are related on explains EXACTLY why the fails occur where they do.
HOWEVER if I look in relationship on database tools for the back end database I can not see where the relationship has been formed so now I know what the problem is I have no idea how to fix it!
********
Edit 4
********
OK it's now working.
I went into relationships and added the Field Symptom table and a link was made to the MyControl table which was already present linked to some other table. I deleted that link and it all works fine now..
So the 64,000 dollar/pound/yen question is how did the relationship get there in the first place? There was no sight of the Field Symptoms table in the relationship part of database tools until Iadded it in there and it automatically linked to MyControls?????