Trouble requerying subreport on tab control

Sketchin

Registered User.
Local time
Yesterday, 23:14
Joined
Dec 20, 2011
Messages
580
Hey ALl,

I have a form with a tabbed control on it. The tabbed control has 4 tabs that each have a report on them. When I select a company name on the main form, I requery these 4 reports to show data related to that company.

For some strange reason, 2 of my reports requery with no problem, and 2 of them give me a message that the report can't be found. Here is the code:

Code:
Private Sub cboCompanyName_AfterUpdate()
On Error GoTo cboCompanyName_AfterUpdate_Err

   ' DoCmd.SearchForRecord , "", acFirst, "[CompanyID] = " & str(Nz(Screen.ActiveControl, 0))
    
' After selecting a company, requery the subreports to display the appropriate data

' These 2 work
Forms!frmCompanyHistory!RptCompany_Projects_Brief.Requery
Forms!frmCompanyHistory!RptEmployeesSpecificCompany.Requery
'These 2 Fail
[COLOR="Red"]Forms!frmCompanyHistory!SubRptCompany_Payback.Requery
Forms!frmCompanyHistory!SubRptCompany_Revenue.Requery
[/COLOR]
'Other things I've tried
'Forms!frmCompanyHistory!TabCtl66!SubRptCompany_Payback.Requery
'Me.TabCtl66!SubRptCompany_Revenue.Requery

As a side note, if I chose the company, say "ok" to the error, and then go run the queries that these reports are based on, I get the correct records. Also, if I chose the company and run the 2 failing reports standalone, they work fine, so I know the problem isn't the reports or the queries themselves.

I have also checked and rechecked for any spelling mistakes and have found none. I should mention that the error message is "Programs cannot find the field 'SubrptCompany_Payback' referred to in your expression".
 
Try:-
Msgbox " >>> " & Forms!frmCompanyHistory!SubRptCompany_Payback.Form.Name

What do you get?
 
Last edited:
I get a box popping up saying ">>> frmCompanyHIstory"
 
Its interesting...if I type this:

MsgBox " >>> " & Me.RptCompany_Projects_Brief.Name

I get a popup saying ">>>Rptcompany_Projects_brief

If I type this:

MsgBox " >>> " & Me.RptCompany_Payback.Name

I get a method or data member not found!?
 
So you have got frmCompanyHistory as your Main form and then you got frmCompanyHistory as a subform within your main form?
 
Oh for %^&$ sakes. I needed to refer to the reports name property, rather than the actual objects name.

Thanks for getting me pointed in the right direction Uncle Giz!
 
Yes .. a typo of sorts... I'm surprised it worked at all.

MS say:- "You can't place a form (or report) within itself"
 
Last edited:
(Edited)
Unfortunately when you drag a form on to a form to create a subform, MS Access names the subform/subreport control to the same name as the form within it! This causes no end of confusion, particularly for people new to MS Access, and me on occasion. Hence my suggestion, here below...

I see you use a naming convention as in:-frmCompanyHistory

I would suggest using a naming convention for the subform/subreport controls

Like change:- SubRptCompany_Revenue

To:-
subFrmWinFrmRptCompany_Revenue

Read "subFrmWin"

As Subform Window, not really a window but it is a more natural fit with the way to think about it.

It's not in any naming convention either...!!
 
Last edited:
You say you're calling the reports from the main form so you can use the "Me." reference or write your code like this:
Code:
    With Me
        .RptCompany_Projects_Brief.Requery
        .RptEmployeesSpecificCompany.Requery
        'These 2 Fail
        .SubRptCompany_Payback.Requery
        .SubRptCompany_Revenue.Requery
    End With
That aside, what's your reason for using a report in a form? And why are you needing to requery?
Secondly, it's not finding it because you're probably referring to the name of the report but not the name of the control that houses the report.
 

Users who are viewing this thread

Back
Top Bottom