0

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 Answer 1

2

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  
Sign up to request clarification or add additional context in comments.

3 Comments

@sabari add more code please. When do you open the form? is it a dialog form? I need more details.
@sabari as you can see, your code is different from my answer. You must first open the form and then set the field. Unless the form has the modal property set to True. Then you need to do what I described in the first case.
Declare the global variable in Module is the perfect solution. worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.