Form Not Opening Right

  • Thread starter Thread starter Ripper
  • Start date Start date
R

Ripper

I am using the following code from to open a form from another continuous
form.
DoCmd.OpenForm "frmDhallAddExpiredRefRecy", , , , acFormAdd, , [DHallID]
= Me.DHallID

However, the form opens except that the DhallID does not transfer. Does
anyone know what I am doing wrong? The DhallID is an autonumber field.
 
Ripper said:
I am using the following code from to open a form from another continuous
form.
DoCmd.OpenForm "frmDhallAddExpiredRefRecy", , , , acFormAdd, , [DHallID]
= Me.DHallID

However, the form opens except that the DhallID does not transfer. Does
anyone know what I am doing wrong? The DhallID is an autonumber field.

Your two arguments are working against each other.

That last argument is a WHERE clause that applies a filter to the form
being opened. That is normally used to see existing records in the
form being opened.

If you open a form with acFormAdd then you are asking it to open in
DataEntry mode for inserting new records and it will NOT show existing
records.

So, which behavior do you want?
 
Ripper said:
I am using the following code from to open a form from another continuous
form.
DoCmd.OpenForm "frmDhallAddExpiredRefRecy", , , , acFormAdd, , [DHallID]
= Me.DHallID

However, the form opens except that the DhallID does not transfer. Does
anyone know what I am doing wrong? The DhallID is an autonumber field.


When you use the OpenArgs argument, it only passes it as a
text string to the form. You need to add some code to the
form's Open event to make use of the argument: In this
case, I think you want something like:

If Not IsNull(Me.OpenArgs) Then
Me.DHallID.DefaultValue = """" & Me.OpenArgs & """"
End If

The OpenForm line would then be:

DoCmd.OpenForm "frmDhallAddExpiredRefRecy", , , ,
acFormAdd, , Me.DHallID
 
Rick Brandt said:
Ripper said:
I am using the following code from to open a form from another
continuous
form.
DoCmd.OpenForm "frmDhallAddExpiredRefRecy", , , , acFormAdd, ,
[DHallID]
= Me.DHallID

However, the form opens except that the DhallID does not transfer. Does
anyone know what I am doing wrong? The DhallID is an autonumber field.

Your two arguments are working against each other.

That last argument is a WHERE clause that applies a filter to the form
being opened. That is normally used to see existing records in the
form being opened.

If you open a form with acFormAdd then you are asking it to open in
DataEntry mode for inserting new records and it will NOT show existing
records.

So, which behavior do you want?

In addition, the last argument is incorrect: there are no quotes around the
field name.

DoCmd.OpenForm "frmDhallAddExpiredRefRecy", _
, , , acFormAdd, , "[DHallID] = " & Me.DHallID
 
Douglas said:
Ripper said:
I am using the following code from to open a form from another
continuous
form.
DoCmd.OpenForm "frmDhallAddExpiredRefRecy", , , , acFormAdd, ,
[DHallID]
= Me.DHallID
[]
That last argument is a WHERE clause that applies a filter to the form
being opened. That is normally used to see existing records in the
form being opened.

In addition, the last argument is incorrect: there are no quotes around the
field name.

DoCmd.OpenForm "frmDhallAddExpiredRefRecy", _
, , , acFormAdd, , "[DHallID] = " & Me.DHallID


Confused? ;-)

Without the quotes the OpenArgs value that will be passed to
the report wil be "-1"
 
Douglas said:
Rick Brandt said:
Ripper said:
I am using the following code from to open a form from another
continuous
form.
DoCmd.OpenForm "frmDhallAddExpiredRefRecy", , , , acFormAdd, ,
[DHallID]
= Me.DHallID

However, the form opens except that the DhallID does not transfer. Does
anyone know what I am doing wrong? The DhallID is an autonumber field.

Your two arguments are working against each other.

That last argument is a WHERE clause that applies a filter to the form
being opened. That is normally used to see existing records in the
form being opened.

If you open a form with acFormAdd then you are asking it to open in
DataEntry mode for inserting new records and it will NOT show existing
records.

So, which behavior do you want?

In addition, the last argument is incorrect: there are no quotes around the
field name.

DoCmd.OpenForm "frmDhallAddExpiredRefRecy", _
, , , acFormAdd, , "[DHallID] = " & Me.DHallID

Okay, I wasn't paying close enough attention. It looked like a WHERE
clause so I assumed that was the WHERE argument of OpenForm(). Marshall
correctly saw that it is actually the OpenArgs argument so now I have
know idea what the OP's intent is.

This looks like it was cobbled together from multiple examples all
trying to do different things.
 
Rick said:
Ripper wrote:
I am using the following code from to open a form from another
continuous form.
DoCmd.OpenForm "frmDhallAddExpiredRefRecy", , , , acFormAdd, ,
[DHallID] = Me.DHallID

However, the form opens except that the DhallID does not transfer.
[snip]
so now I have no idea what the OP's intent is.

Reading between the lines, I guessed that Ripper expected
the VBA assignment statement to set the value in the form's
new record, but you're right, there is a myriad of potential
interpretations.
 
Back
Top