DefaultValue in Form Normal View

  • Thread starter Thread starter Rajesh B. Patel
  • Start date Start date
R

Rajesh B. Patel

Hi,

When I open a form in acNormal view and acDialog window mode I cannot
set the DefaultValue property for a text field in the form since the
code after the DoCmd.OpenForm does not execute until after I exit the form.

If I open the form in acFormDS view then this works just fine. Here are
the code snippets:

In acNormal view:

DoCmd.OpenForm "frm_Hospitalization_Labs", acNormal, , , , acDialog,
strSelect

With Forms![frm_Hospitalization_Labs]
![txtID].DefaultValue = HospitalizationID
End With

----------

In acFormDS view:

DoCmd.OpenForm "frm_Hospitalization_Labs", acFormDS, , , , acDialog,
strSelect

With Forms![frm_Hospitalization_Labs]
![txtID].DefaultValue = HospitalizationID
End With

----------

In both cases strSelect is a string representing a sql query that I
set the frm_Hospitalization_Labs.RecordSource to in the Form_Open event.
Also, I am doing all of this in a Button_Click event (not that it matters).

Any idea why this does not work in both cases? I want to present this
form in acNormal view. Could this be an access bug?

Thanks.

raj
 
Rajesh B. Patel said:
Hi,

When I open a form in acNormal view and acDialog window mode I cannot
set the DefaultValue property for a text field in the form since the
code after the DoCmd.OpenForm does not execute until after I exit the form.

If I open the form in acFormDS view then this works just fine. Here are
the code snippets:

In acNormal view:

DoCmd.OpenForm "frm_Hospitalization_Labs", acNormal, , , , acDialog,
strSelect

With Forms![frm_Hospitalization_Labs]
![txtID].DefaultValue = HospitalizationID
End With

----------

In acFormDS view:

DoCmd.OpenForm "frm_Hospitalization_Labs", acFormDS, , , , acDialog,
strSelect

With Forms![frm_Hospitalization_Labs]
![txtID].DefaultValue = HospitalizationID
End With

----------

In both cases strSelect is a string representing a sql query that I
set the frm_Hospitalization_Labs.RecordSource to in the Form_Open event.
Also, I am doing all of this in a Button_Click event (not that it matters).

Any idea why this does not work in both cases? I want to present this
form in acNormal view. Could this be an access bug?

You already said it. One of the main reasons to use acDialog is to pause
the calling code until the form is either hidden or closed so that is
working as designed. If you don't want the code to pause then don't use
the acDialog argument.

If you just want to force the user to deal with the form then set the modal
and popup properties to True. That has the same effect as acDialog without
the code-pausing behavior.
 
You already said it. One of the main reasons to use acDialog is to pause
the calling code until the form is either hidden or closed so that is
working as designed. If you don't want the code to pause then don't use
the acDialog argument.

If you just want to force the user to deal with the form then set the modal
and popup properties to True. That has the same effect as acDialog without
the code-pausing behavior.

Thanks for your reply.

I am still not sure why it continues to execute the code in the calling
routine when I change to acFormDS view?

Any ideas? (just curious)

raj
 
Rajesh B. Patel said:
Thanks for your reply.

I am still not sure why it continues to execute the code in the calling
routine when I change to acFormDS view?

Any ideas? (just curious)

Because datasheet view inhibits the acDialog option. I'm not sure why, but
Access does not allow a datasheet form to also be in dialog mode.
 
Back
Top