title: MS Access - opening a form with a new record and inserting a value from a previous form
body: <p>I have a form in an MS Access database which lists Orders with an Order Number with one order per page. At the bottom of the form there is a button which opens another form, to add an item for the order.</p>
  
  <p>I am trying to use vb in MS Access to take the order number and automatically put it in a field in the details form for the new item. I have tried different ways but using OpenArgs seems to be recommended. But the detail form won't open and I get run-time errors. 
  Here are the details of the problem - advice will be much appreciated:</p>
  
  <p>The forms and field concerned are:
  Form with orders is frmPedidoAvifiFind
  Form with order-lines for one order is frmPedidoAvifi-dtlAdd (a separate form for adding details but not for viewing existing ones).
  Field on both forms for Order Number is PedidoAvifiNo. This is a numeric field in both tables which are linked by a one-to-many relation via this field.</p>
  
  <p>Main form: Button bring up detail form, code as follows:</p>
  
  <p>Code on main form button:</p>
  
  <pre><code>Sub AddDetails_Click()
    Dim strDocName As String
  
      strDocName = "frmPedidoAvifi-dtlAdd"
  
      ' Open frmPedidoAvifi-dtl form in data entry mode and store PedidoAvifiNo in  the form's OpenArgs property.
  
      DoCmd.OpenForm strDocName, , , , acFormAdd, , [frmPedidoAvifiFind]![PedidoAvifiNo]
  
  End Sub
  </code></pre>
  
  <p>Detail form: On Open property </p>
  
  <pre><code>Private Sub Form_Open()
  If Me.OpenArgs &lt;&gt; vbNullString Then
     Me.PedidoAvifiNo = Me.OpenArgs
  End If
  
  End Sub
  </code></pre>
  
  <p>Test 1: select an order number on main form so that record shows.
  Press button to add orderline.  - run-time error '2465'  can't find the field "|" referred to. Debug highlights the DoCmd line.</p>
  
  <p>Test 2:
  Change openform line to:
  DoCmd.OpenForm strDocName, , , , acFormAdd, , Me.PedidoAvifiNo
  result:  - run-time error 2501 the openForm action was canceled.</p>
  
  <p>Thank you,
  Mike Gunner
  Reus, Spain</p>