If i call another AfterUpdate i get a 3075 error (1 Viewer)

manosalexo

New member
Local time
Today, 05:17
Joined
Jan 25, 2019
Messages
6
Hello,

I have a situation.
I have built a form in which at the product's afterupdate event i have inserted the following:

Private Sub Product_AfterUpdate()
Me.Category = DLookup("[Category_table.Description]", "Query3", "[product_id]=" & Forms!order!Product)
Me.plaisio_idd = DLookup("[plaisio_id]", "Products", "[product_id]=" & Forms!order!Product)
Me.color_description = Null
Me.color_description.Requery
Me.color_description = DLookup("[color_description]", "Query1", "[product_id]=" & Forms!order!Product)
Me.Price = DLookup("[price]", "Products", "[product_id]=" & Forms!order!Product)
Me.measurement_unit = DLookup("[measurement_unit]", "Products", "[product_id]=" & Forms!order!Product)
End Sub

Now what i am trying to do is to Call that event from another afterupdate so that the user may either select the product, or enter the ID:
Private Sub plaisio_idd_AfterUpdate()
Me.Product.Requery
Me.Product = DLookup("[description]", "[Products]", "[plaisio_id]=" & Forms!order!plaisio_idd)
Call Product_AfterUpdate
End Sub

Now when i insert these lines of code, the debugger hits a 3075 error in my Product_AfterUpdate() code. If i remove plaisio_idd_AfterUpdate(), my Product_AfterUpdate works just fine.

Can someone please tell me what i'm doing wrong?
Thank you in advance
 

Ranman256

Well-known member
Local time
Yesterday, 22:17
Joined
Apr 9, 2015
Messages
4,337
why are you doing 3 things here? :

Me.color_description = Null
Me.color_description.Requery
Me.color_description = DLookup("[color_description]", "Query1", "[product_id]=" & Forms!order!Product)

just do 1.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 21:17
Joined
Feb 28, 2001
Messages
27,167
Make that section of the Product_AfterUpdate() code that is relevant into a separate subroutine in the class module. If you have trouble because of the use of "Me" in the routine, make it have a formal parameter that is an Access form. Then call the subroutine from both events with "Me" as an argument.

Code:
Private Sub SelectOrChange( F as Access.Form )
  F.Category = Dlookup( "F.[Category_table.Descripton]", "Query3", "[Product_ID]=...etc
  F.Color_Description = Null
... etc.
End

Use F in the subroutine whenever you refer to a control on that form. (In your second event sub, the "Me" references outside the new subroutine do not change), call it with

Code:
    Call SelectOrChange( Me )
 

manosalexo

New member
Local time
Today, 05:17
Joined
Jan 25, 2019
Messages
6
why are you doing 3 things here? :

Me.color_description = Null
Me.color_description.Requery
Me.color_description = DLookup("[color_description]", "Query1", "[product_id]=" & Forms!order!Product)

just do 1.

You're right, changed that but the problem still remains:banghead:
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:17
Joined
Feb 19, 2002
Messages
43,257
There are better ways to do this. I've attached a sample database that shows a better solution.
 

Attachments

  • FillFormFields20180816.zip
    342.4 KB · Views: 115

manosalexo

New member
Local time
Today, 05:17
Joined
Jan 25, 2019
Messages
6
Make that section of the Product_AfterUpdate() code that is relevant into a separate subroutine in the class module. If you have trouble because of the use of "Me" in the routine, make it have a formal parameter that is an Access form. Then call the subroutine from both events with "Me" as an argument.

Code:
Private Sub SelectOrChange( F as Access.Form )
  F.Category = Dlookup( "F.[Category_table.Descripton]", "Query3", "[Product_ID]=...etc
  F.Color_Description = Null
... etc.
End

Use F in the subroutine whenever you refer to a control on that form. (In your second event sub, the "Me" references outside the new subroutine do not change), call it with

Code:
    Call SelectOrChange( Me )

Tried it and the problem appears at the "F." declarations section this time.

update: It now shows run-time error 3126
 
Last edited:

Users who are viewing this thread

Top Bottom