Open form Order based on IDCustomer on new record

J

John B

Hello,
with the following code associated to a button I open the form Order
DoCmd.OpenForm "Order", acFormAdd, , , , , Me.IDCustomer
It works fine, but it opens the form "Order" on an old order.
I would like that the form "Oder" open on new record, based on IDCustomer.
How may I do this?

Thanks and Regards
JohnB
 
F

fredg

Hello,
with the following code associated to a button I open the form Order
DoCmd.OpenForm "Order", acFormAdd, , , , , Me.IDCustomer
It works fine, but it opens the form "Order" on an old order.
I would like that the form "Oder" open on new record, based on IDCustomer.
How may I do this?

Thanks and Regards
JohnB

How does this work fine?
You have the acFormAdd argument in the place where you would normally
have acDesign or acNormal,, etc. and you have the IDCustomer (I assume
that is a field name) in the OpenArgs argument position.
You code would not open filtered on any order as you are opening it in
acFormAdd (ready to enter a new order).

I think you mean you wish to pass the current IDCustomer value to the
other form which will open to a new record with the IDCustomer value
already filled in. Is that correct?

Try this:

DoCmd.OpenForm "Order", , , , acFormAdd , , Me.[IDCustomer]

Make sure you place the commas exactly as I have them above.

Then code the Order form's Load event:
If Not IsNull(Me.OpenArgs) Then
Me.[Control Name on Order form] = Me.OpenArgs
End If

However, the [Control Name on Order Form] cannot be an AutoNumber
field.
 
J

John B

Thanks for your prompt reply.

I think you mean you wish to pass the current IDCustomer value to the
other form which will open to a new record with the IDCustomer value
already filled in. Is that correct? YES

Try this:
DoCmd.OpenForm "Order", , , , acFormAdd , , Me.[IDCustomer]

However the code stop where indicated. Is because Me.[IDCustomer] is
numeric?

If Not IsNull(Me.OpenArgs) Then
Me.[IDCustomer] = Me.OpenArgs 'It stops here with null value.
End If

Thanks for Your help.
Regards
John B
 
F

fredg

Thanks for your prompt reply.
I think you mean you wish to pass the current IDCustomer value to the
other form which will open to a new record with the IDCustomer value
already filled in. Is that correct? YES

Try this:
DoCmd.OpenForm "Order", , , , acFormAdd , , Me.[IDCustomer]

However the code stop where indicated. Is because Me.[IDCustomer] is
numeric?

If Not IsNull(Me.OpenArgs) Then
Me.[IDCustomer] = Me.OpenArgs 'It stops here with null value.
End If

Thanks for Your help.
Regards
John B

Precisely where (which form ... which event) did you place this code?

If Not IsNull(Me.OpenArgs) Then
Me.[IDCustomer] = Me.OpenArgs 'It stops here with null value.
End If

It belongs in the Order form's Load event.

Try this in the Order form's Load event.

MsgBox "The OpenArgs value is " & Me.OpenArgs
If Not IsNull(Me.OpenArgs) Then
Me.[IDCustomer] = Me.OpenArgs 'It stops here with null value.
End If

When you open the Order form you will get a message box with the
OpenArgs value. Yes, it's OK if it is a number.

Note my warning in my previous reply. The IDCustomer control on the
Order form can not be an AutoNumber field. It can be Long Integer.
 

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