Multiple Report Instances :how to Set Focus on particular opened instance

informer

Registered User.
Local time
Today, 09:39
Joined
May 25, 2016
Messages
75
Hi

My problem is to set the focus on a particular Report instance opened . I copy a function which works perfectly for form object but not for Report object. My function:

Code:
Function mInstanceReportCA(varYear As Variant)
	   
	Dim oReport As Access.Report
	Dim obj As Object
	
	' Création du nouveau formulaire
	For Each obj In clsReport
		If obj.txtYear = varYear Then
			obj.Visible '---------------------------> Error 438 
			obj.SetFocus '---------------------------> Error 2465
			Exit Function
		End If
	Next obj
	
	Set oReport = New Report_rptCaMois
	
	' Activation du nouveau formulaire
	With oReport
		
		If varYear = "1999" Then
			.txtYear = "1999"
			.Caption = "Rapport toutes années confondues"
			.Filter = "Year(dateFacture) > 1999 "
		Else
			.txtYear = CStr(varYear)
			.Caption = "Rapport pour l'année  " & CStr(varYear)
			.Filter = "Year(dateFacture) = " & varYear
		End If
		.FilterOn = True
		.Visible = True
	End With
	
	
	' Ajout du formulaire à la collection globale
	clsReport.Add Item:=oReport, Key:=CStr(oReport.Hwnd)
   
	Set oReport = Nothing
	
End Function


In the loop routine, These commands below generate error message
Code:
   For Each obj In clsReport
		If obj.txtYear = varYear Then
			obj.Visible '---------------------------> Error 438
			obj.SetFocus '---------------------------> Error 2465
			Exit Function
		End If
	Next obj


thanks for your help :banghead:
 
Report data is controlled from the query,
There's no need for any code.
 
Hi Ranman256,

What do you mean? It's not possible to set focus on a report instance !

In any case, for each report instance, there is an item with its Hwnd in my clsReport collection.


obj.Visible ' Error 438 corrected => obj.Visible = True/False

Any idea about how to to move into the foreground a particular instance?
 
Last edited:
We need to use BringWindowToTop API windows

Declaration on general part module Public Declare Function BringWindowToTop Lib "user32" (ByVal hWnd As Long) As Long

In the code -> BringWindowToTop obj.hwnd

Thanks to Dirk Goldgar
 

Users who are viewing this thread

Back
Top Bottom