DoCmd OpenForm with filter opens in "Add" mode
Posted on 2007-08-03
I have a simple VBA application. On the primary form is a list of equipment in the "Equipment" table. I have a secondary form that displays information on each piece of equipment.
If a user is viewing the equipment list, they double click on a line to view the form that displays details on the equipment.
This is the line of code I am using:
DoCmd.OpenForm "Equipment", acNormal, , strWhere
strWhere is my filter, looking at it in debug shows
[Equipment_ID] = 47,
which is the correct ID of the piece of equipment I clicked on.
The subform opens in "Add" mode, all the fields are blank. If I type in any of the fields it creates a new equipment record. I have a button which intentionally invokes this functionality, but in that case I am calling:
DoCmd.OpenForm "Equipment", , , , acFormAdd
Here is a another piece of the puzzle, I created a new form named "Equipment1" and dropped all of the "Equipment" fields from the table onto the form layout. If I change the text of my OpenForm command to use "Equipment1" instead of "Equipment", the form works fine.
In fact I don't think there are any differences at this point between Equipment and Equipment1, so why would one work and one not.
I did a compact and repair on the database, but that did not make any difference. Any ideas why this would happen?