Hi,
This is a small niggle of a problem that I thought I may as well ask about, rather than just keep putting up with it.
In my forms, I use the following line quite a bit. Often in the Not In List property of a combo box or more simply, a command button to create a new record in another table:
DoCmd.OpenForm "SecondForm", , , , acFormAdd
I then follow it up with lines to automatically fill data:
Forms!SecondForm.CreatedBy = [CurrentUser]
Forms!SecondForm.CreatedWhen = Now()
It works ok most of the time, but sometimes (very random!)it doesn't add a new record. Instead it opens the first record of the table SecondForm is attached to. Then my autofill lines happily overwrite existing data! I've no idea why it does this. If I click the button again without restarting or any other error checking, it works.
As in other parts of the database, I could write a new record direct to the table via a RecordSet, so I suppose I could create the record, then use link criteria to open it in the subform. But that feels like a long winded bodge that won't teach me why it happened!
If it helps to know, the DB is split, so the tables are in a backend.
Cheers!
This is a small niggle of a problem that I thought I may as well ask about, rather than just keep putting up with it.
In my forms, I use the following line quite a bit. Often in the Not In List property of a combo box or more simply, a command button to create a new record in another table:
DoCmd.OpenForm "SecondForm", , , , acFormAdd
I then follow it up with lines to automatically fill data:
Forms!SecondForm.CreatedBy = [CurrentUser]
Forms!SecondForm.CreatedWhen = Now()
It works ok most of the time, but sometimes (very random!)it doesn't add a new record. Instead it opens the first record of the table SecondForm is attached to. Then my autofill lines happily overwrite existing data! I've no idea why it does this. If I click the button again without restarting or any other error checking, it works.
As in other parts of the database, I could write a new record direct to the table via a RecordSet, so I suppose I could create the record, then use link criteria to open it in the subform. But that feels like a long winded bodge that won't teach me why it happened!
If it helps to know, the DB is split, so the tables are in a backend.
Cheers!