Quote:
Originally Posted by Khaelor
Is there an Import API that will give me access to Screen.[whatever]?
|
Pretty much, there is an API that gives you the hWnd (window handle) of the active window, which you can then compare with the UserForms' hWnds, which in turn can also be obtained using API. If you insist on doing it this way, I'll post links to the relevant MSDN pages.
Quote:
|
That is Plan B at the moment, as I already have 3 arguments required for my PrintMe function, and I'd rather not have to have a 4th in there.
|
If you don't mind me saying so, that isn't much of a reason for resorting to API. It's your call, of course, but it seems disproportionate...
Anyway, I don't think you even need to do that. If you are passing the ListView control, you can easily navigate to the form, using .Parent I think. Additionally, your work-around code sample suggests that simply hiding all forms would do the trick.
Quote:
|
When passing a UserForm as an argument, you cannot access the .Hide method on it.
|
This is extremely weird. Somehow, VBA magically adds .Hide, .Show and .Visible to the UserForm interface to create the UserForm1 (etc.) interface. If you search for .Hide in the Object Browser, even including hidden members, nothing related shows up, so I have no idea what's going on.
Nevertheless, this can be compensated for. If your ListView forms are all instances of the same UserForm class, let's call it ListViewContainer, you can do it like
Code:
For Each frm in UserForms
If TypeOf frm Is ListViewContainer Then
Set lvc = frm
lvc.Hide
End If
Next frm
where lvc is declared as ListViewContainer. If they are instances of different UserForm classes, you can create a common interface which exposes the required functionality. You add a class module to your project and name it say IListViewContainer (the leading "I" is not needed but good practice, it marks it as an interface class). Then, you "Implement" this interface in each userform for which it is needed. The code looks like this:
class IListViewContainer
Code:
Public Sub lvcHide()
End Sub
Public Sub lvcShow(fsc As FormShowConstants)
End Sub
Public Property Get lvcVisible() As Boolean
End Property
Public Property Let lvcVisible(RHS As Boolean)
End Property
each UserForm
Code:
Implements IListViewContainer
Private Sub IListViewContainer_lvcHide()
Call Me.Hide
End Sub
Private Sub IListViewContainer_lvcShow(fsc As FormShowConstants)
Call Me.Show(fsc)
End Sub
Private Property Get IListViewContainer_lvcVisible() As Boolean
IListViewContainer_lvcVisible = Me.Visible
End Property
Private Property Let IListViewContainer_lvcVisible(RHS As Boolean)
Me.Visible = RHS
End Property
usage example
Code:
Private Function AsListViewContainer(frm As UserForm) As IListViewContainer
Set AsListViewContainer = frm
End Function
For Each frm in UserForms
If TypeOf frm Is IListViewContainer Then
Call AsListViewContainer(frm).lvcHide
End If
Next frm
So, the loop checks for each form if it is of a type which has the added interface functionality, and if so, uses the function to access that interface and call its lvcHide method. That method, in turn, calls the specific form classes Me.Hide method.
If you haven't used classes before, this may seem a lot of new stuff at once, but if you take it step by step, each one should be quite straightforward to follow, I hope.
