Saturday, 24 August 2013

Doing a Requery on a Form opened with acFormAdd creates a new record

Doing a Requery on a Form opened with acFormAdd creates a new record

Lets asume a user wants to create a new record and to do so he opens a
form. When opening a form with
DoCmd.OpenForm "FormName", acNormal, "", "", acFormAdd, acDialog
Access will open the form with the data pointer set on a new/empty record.
The user can now fill the form but some user actions may require a
Me.Requery in order to take place. If you do so, the form "looses" the
data pointer on the currently created and modified record and jumps to a
new, empty record. Even a Me.Dirty = False before the requery wont prevent
Access from doing so. Im pretty sure this behavior results from the
paramter acFormAdd.
In contrast, opening a form with
DoCmd.OpenForm "FormName", acNormal, "", "WHERE-CLAUSE", acFormEdit, acDialog
resolves the behavior but will only work for existing records.
You can imagine that this unrequested behavior is not what I'm expecting
because it forces me to implement an ugly workaround with closing and
reopening the from when certain conditions are fulfilled.
So, I'm wondering if there is a much easier way that helps me avoid the
behevior described above. I would very much appreciate your assistance!

No comments:

Post a Comment