Open a new form based on form but has a subform (1 Viewer)

Number11

Member
Local time
Today, 15:22
Joined
Jan 29, 2020
Messages
607
I have a form created called "View_Orders" it has a subform called "Order", I have added a button to open a new form but its not working getting error saying it cant find "ORDER_ACCOUNT_NO" referred to in your expressions. guessing its because the field is within the sub form


DoCmd.OpenForm "New Form", acNormal, , "[Order_Number]=" & Me![ORDER_ACCOUNT_NO]

How would I go about changing the form to look at "View_Orders" sub form?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:22
Joined
May 7, 2009
Messages
19,248
dont you think "New Form" there should be "View_Orders"?
 

Number11

Member
Local time
Today, 15:22
Joined
Jan 29, 2020
Messages
607
dont you think "New Form" there should be "View_Orders"?
Sorry yes thats correct still getting same error message

DoCmd.OpenForm "View_Orders", acNormal, , "[Order_Number]=" & Me![ORDER_ACCOUNT_NO]
think the issue is with the & Me![ORDER_ACCOUNT_NO] as this is not on the Order form is on the sub form called Picking
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:22
Joined
May 7, 2009
Messages
19,248
what you can do is pass your Criteria as OpenArgs:

DoCmd.OpenForm FormName:="View_Orders", View:=acNormal, OpenArgs:="[Order_Number]=" & Me![ORDER_ACCOUNT_NO]


before you run the code, open "Order" subform in design view.
add code to it's Load Event:

Code:
Private Sub Form_Load()
    Dim sFilter As String
    sFilter = Me.Parent.OpenArgs & ""
    If Len(sFilter) Then
        Me.Filter = sFilter
        Me.FilterOn = True
    End If
End Sub
 

Minty

AWF VIP
Local time
Today, 15:22
Joined
Jul 26, 2013
Messages
10,371
No, you have mixed up my post and Arnelgp's suggestion.
Do one or the other, not both.

Mine will only work if the value you need is on a subform on the form where the button is pressed.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:22
Joined
May 7, 2009
Messages
19,248
describe your First form (where you use DoCmd.OpenForm), does it has a subform? what is the name of the subform?
my code will filter the (subform) of the Form you are trying to open.
 

Number11

Member
Local time
Today, 15:22
Joined
Jan 29, 2020
Messages
607
describe your First form (where you use DoCmd.OpenForm), does it has a subform? what is the name of the subform?
my code will filter the (subform) of the Form you are trying to open.
The main form is called "View_Orders" it has a subform called "Orders" with one of the fields being called "ORDER_ACCOUNT_NO"

which form do i put the code Load Event?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:22
Joined
May 7, 2009
Messages
19,248
so Minty's suggestion will work for you:

DoCmd.OpenForm FormName:="DATA_VIEW", View:=acNormal, WhereCondition:="[Order_Number]=" & Forms!View_Orders!Orders.Form!Order_Account_Number
 

Number11

Member
Local time
Today, 15:22
Joined
Jan 29, 2020
Messages
607
so Minty's suggestion will work for you:

DoCmd.OpenForm FormName:="DATA_VIEW", View:=acNormal, WhereCondition:="[Order_Number]=" & Forms!View_Orders!Orders.Form!Order_Account_Number
Thanks for your help its not working getting this..
1674828895260.png
 

Minty

AWF VIP
Local time
Today, 15:22
Joined
Jul 26, 2013
Messages
10,371
With 500+ posts you should know that you need to post up the code you have used, so we might be able to see what you have not got right?
 

Users who are viewing this thread

Top Bottom