0
votes

I am having two forms OrderForm and CustomerForm.

In CustomerForm, I have a combo box, in which I select the orderId. If I click 'View' button , then it should show me a pop up which contains the order details of THIS 'orderId'

CustomerForm

  • orderId stored in cbxOrderId
  • viewOrderBut - button to display orderForm popup

I tried like below and failed

viewOrderBut click event

Forms![OrderForm].orderId = orderIdVar  

Error:

Cannot find the referenced Form 'OrderForm'

my orderId variable in OrderForm is public

public orderId as string

Someone Please help me.

Editing

Code :

CustomerForm :

Public gblorderId as string



    Private Sub btnApproval_Click()
    gblOrderId = "123" 'static assignment of order id
    DoCmd.OpenForm "OrderForm"
    End Sub 

OrderForm

Public orderId as string

Private Sub Form_Load()
orderId = gblOrderID
MsgBox("orderId="+orderId)
End sub

Error:

Prints...

orderId=

how to refer to CustomerForm.gblOrderId from OrderForm. I guess there i am missing.

1

1 Answers

2
votes

The error suggests that the form OrderForm cannot be found. Have you opened the form beforehand?

  1. If OrderForm is a dialog form, then

This should be the code for your button :

orderIdVar = Forms!CustomerForm!comboBoxOrderId
docmd.openform "OrderForm"

and in the Form_load event of the OrderForm

me.orderId = orderIdVar

2.Otherwise

this :

docmd.openform "OrderForm"
Forms![OrderForm].orderId = orderIdVar