Form Not Opening Right

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.
 
R

Rick Brandt

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?
 
M

Marshall Barton

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
 
D

Douglas J. Steele

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
 
M

Marshall Barton

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"
 
R

Rick Brandt

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.
 
M

Marshall Barton

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top