Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Requery 2 forms, avoid error 2450

Status
Not open for further replies.

dpav29

Technical User
Aug 3, 2001
155
US
I'm so close. . .

Private Sub Form_Close()
If Forms!Switchboard!frmAllRebatesDue.Visible = True Then
Forms!Switchboard!frmAllRebatesDue.Requery
End If
If Forms!frmVendorMain!frmVendorGen.Visible = True Then
Forms!frmVendorMain!frmVendorGen.Requery
End If

The second form won't requery. . .I know I should be able to do this, but I haven't been able to hack my way through it!

Is there some sort of "ThenIf" to pick up the second one? I've tried else, but that doesn't work if the first form is visible (it ends the sub at that point). Please help!
 
Try this:
Forms!frmVendorMain!frmVendorGen.Form.Requery

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for the reply!

No, that's not doing it.

I can make it work for one form or the other the way I have it:

Private Sub Form_Close()
If Forms!Switchboard!frmAllRebatesDue.Visible = True Then
Forms!Switchboard!frmAllRebatesDue.Requery
End If

The trouble is that I want to requery the second form as well if it is visible. What's the test to look for the second one and requery both if they are both open?
 
Still trying to figure this out and thought about doing something like:

First form requeries on the unload event, second one on the close event. . maybe:

Private Sub Form_Unload()
If Forms!Switchboard!frmAllRebatesDue.Visible = True Then
Forms!Switchboard!frmAllRebatesDue.Requery
End If

Private Sub Form_Close()
If Forms!frmVendorMain!frmVendorGen.Visible = True Then
Forms!frmVendorMain!frmVendorGen.Requery
End If

Anyway, that's not working either. Am I barking up the wrong tree here?

Any help is appreciated as always!
 
I know this isnt the right way to go around it but try
Code:
Private Sub Form_Close()
If Forms!Switchboard!frmAllRebatesDue.Visible = True Then
Forms!Switchboard!frmAllRebatesDue.Requery
If Forms!frmVendorMain!frmVendorGen.Visible = True Then
Forms!frmVendorMain!frmVendorGen.Requery
End If
else
If Forms!frmVendorMain!frmVendorGen.Visible = True Then
Forms!frmVendorMain!frmVendorGen.Requery
End If
End If





TechnicalUser pretending to be a programmer(shhh… the boss doesn’t know yet)
 
How are ya dpav29 . . . . .

According to your description of the problem, my first suspision saids transfer the code to the [blue]UnLoad[/blue] event and try again . . .

Calvin.gif
See Ya! . . . . . .
 
Thanks a lot for your responses folks, but no luck with either suggestion.

In both cases, if VendorMain!VendorGen is closed, I get the runtime error 2450 (can't find the form. . . ).

I hate to do it, but my work-around may have to be to keep both forms open all the time . . one on top of the other (unless you can think of anything else).

Again, thanks so much for your time and help!
 
dpav29 said:
[blue]In both cases, if VendorMain!VendorGen [purple]is closed[/purple], I get the runtime error 2450 (can't find the form. . . ).

I hate to do it, but my work-around [purple]may have to be to keep both forms[/purple] open all the time[/blue]
This is the problem in a nutshell; [purple]The forms have to be open[/purple] in order to work with them. reason being:
[blue]In the reference [purple]Forms[/purple]!FormName1!FormName2 . . . . .

[purple]Forms[/purple] is the collection of all open forms![/blue]

Calvin.gif
See Ya! . . . . . .
 
To check if a form is loaded, the Northwind sample database comes with an IsLoaded function, there also one available in Rohdems faq faq181-320. Try that prior to testing the visible property of the forms (and yes, as TheAceMan1 stated, a form must be open to address such properties).

Roy-Vidar
 
dpav29 . . . . .

Hit submit by accident. This is continuation of my last post.

Although you didn't indicate a form could be closed, this is exactly what you need to detect. Bear in mind you can't detect if a subform is open [blue](since its really a control on the parent form)[/blue], but you can detect the main/parent form.

So copy/paste the modified code below.
Code:
[blue]   Dim frm As Form, sfrm As Form, frmX As Form
   Dim frmName1 As String, sfrmName1 As String
   Dim frmName2 As String, sfrmName2 As String
   
   frmName1 = "Switchboard"
   sfrmName1 = "frmAllRebatesDue"
   frmName2 = "frmVendorMain"
   sfrmName2 = "frmVendorGen"
   
   For Each frmX In Forms [green]'Detect if forms are open[/green]
      If frmX.Name = frmName1 Or frmX.Name = frmName2 Then
         Set frm = Forms(frmX.Name)
         
         If frmX.Name = frmName1 Then
            Set sfrm = frm(sfrmName1).Form
         Else
            Set sfrm = frm(sfrmName2).Form
         End If
         
         [purple][b]If sfrm.Visible Then sfrm.Requery[/b][/purple]
         
         Set sfrm = Nothing
         Set frm = Nothing
      End If
   Next[/blue]
Give it a whirl and let me know . . . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top