Link to home
Start Free TrialLog in
Avatar of compsol1993
compsol1993

asked on

DoCmd OpenForm with filter opens in "Add" mode

Hello,

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?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<The subform opens in "Add" mode>
Did you check the DataEntry property of the subform?

a
Avatar of compsol1993
compsol1993

ASKER

Thanks for the feedback  

capricorn1:  I had already tried your suggestions.  Since the primary key of the table is an autonumber, trying to change it in form load() produces an error saying that the field cannot be edited.  It seems that it is already in add mode at that point.

is equipment_id an autonumber ?
if it is opening the form in addmode will automatically create a equipment_id.
what is it you are trying to do?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
did you check the dataentry property?