Run-time error ‘2450’: (1 Viewer)

browninaz

Ugly Data Hoarder
Local time
Today, 10:16
Joined
Oct 26, 2012
Messages
88
Hello everyone,


When I update the data in frmPurchasesEquipment, I get the run-time error message:

Microsoft Access cannot find the referenced form’frmPurchasesLivestockPlants’.

I have requery code set to refresh the data in my combo boxes on 3 separate modal dialogue forms that the same data can be entered in. The problem I have is, when the event is triggered, the code is looking for forms that are not open. Here is the code:

Private Sub Form_Unload(Cancel As Integer)

Forms!frmPurchasesLivestockPlants!frmPlantLivestockPurchaseDetailsSubform!cboSetupNum.Requery

Forms!frmPurchasesHardscape!frmEquipmentPurchaseDetailsSubform!cboSetupNum.Requery

Forms!frmPurchasesEquipment!frmHardscapePurchaseDetailsSubform!cboSetupNum.Requery

End Sub

I guess the question is obvious... How do I get the requery code to work on one form without it trying to find the other forms when they are not in use?

Thanks to all that are smarter than me.
 
Last edited:

MarkK

bit cruncher
Local time
Today, 10:16
Joined
Mar 17, 2004
Messages
8,178
I would expect there to only be one Purchases form that is capable of displaying different types of items by applying a filter to the form, not by having differently named versions to handle different type of Products. Typically you want those kinds of type distinctions to be handled as filterable data, not as additional un-filterable objects in your database.
 

browninaz

Ugly Data Hoarder
Local time
Today, 10:16
Joined
Oct 26, 2012
Messages
88
Thanks sneuberg for the quick response,

I don't think that was quite what I was looking for. I need to find a way to not execute the code for the forms that are not open or being used. I have very little VBA coding knowledge, and I was fortunate enough to obtain the code that I do have already from some of the nice folks that belong to this forum.
 

sneuberg

AWF VIP
Local time
Today, 10:16
Joined
Oct 17, 2014
Messages
3,506
If you change the code to

Code:
Private Sub Form_Unload(Cancel As Integer)

If CurrentProject.AllForms("frmPurchasesLivestockPlants").IsLoaded Then
    Forms!frmPurchasesLivestockPlants!frmPlantLivestockPurchaseDetailsSubform!cboSetupNum.Requery
End If
If CurrentProject.AllForms("frmPurchasesHardscape").IsLoaded Then
    Forms!frmPurchasesHardscape!frmEquipmentPurchaseDetailsSubform!cboSetupNum.Requery
End If
If CurrentProject.AllForms("frmPurchasesEquipment").IsLoaded Then
    Forms!frmPurchasesEquipment!frmHardscapePurchaseDetailsSubform!cboSetupNum.Requery
End If

End Sub

I think that would take care of the error. If you need to do something more please elaborate on what you need to do. It might help if you uploaded your database and gave us an example of what you need to work differently.
 

browninaz

Ugly Data Hoarder
Local time
Today, 10:16
Joined
Oct 26, 2012
Messages
88
sneuberg, that looks like it will be awesome! Give me a little while to implement and I will let you know if it works.
 

browninaz

Ugly Data Hoarder
Local time
Today, 10:16
Joined
Oct 26, 2012
Messages
88
sneuberg, thank you so much! That did it.
 

Users who are viewing this thread

Top Bottom