visible = true is false

John Sh

Member
Local time
Tomorrow, 02:06
Joined
Feb 8, 2021
Messages
493
In the code below, line 4, "sTable" is recognised as not visible but the "forms(stable).visible = true" does nothing.
Tried it with and without the "Refresh", still the form "sTable" remains invisible.
Code:
Public Sub isOpen(sTable As String)
    If Len(sTable) > 0 Then
        If CurrentProject.AllForms(sTable).IsLoaded = True Then
            If Forms(sTable).Visible = False Then Forms(sTable).Visible = True
            Forms(sTable).Refresh
        End If
End Sub
 
The referenced form is a standalone, not a subform?
 
The function shown cannot run. An End If is missing.

BTW:
The parameter sTable was named this way because you want to pass a form name? ;)
 
I also just noticed missing End If. Posted code should fail to run.
 
I also just noticed missing End If. Posted code should fail to run.
This is not the complete sub., only the bit relevant to the problem.
In essence, a form, sTable, calls another form and sTable goes invisible.
The second form then calls sTable making itself invisible and sTable visible.
Only problem is sTable stays invisible.
here is the complete sub.

Code:
Public Sub isOpen(sTable As String)
    If Len(sTable) > 0 Then
        If CurrentProject.AllForms(sTable).IsLoaded = True Then
            If Forms(sTable).Visible = False Then Forms(sTable).Visible = True
            Forms(sTable).Refresh
            If sTable = "Multi-Search" Then Forms(sTable).txtGoto_2 = ""
        Else
            DoCmd.OpenForm sTable, , , , , , sForm
        End If
    Else
        DoCmd.OpenForm "Anomalies", , , , , , "Quick"
    End If
End Sub
 
Did you step through the code? Is it actually evaluating the condition properly as you expect at that stage? Where does this code reside? Is it in it's own module or is it part of a particular form? The name of the sub is isOpen which suggests that it should be a function that returns a True/False value. It's just not clear what this is supposed to do.

In essence, a form, sTable, calls another form and sTable goes invisible.
The second form then calls sTable making itself invisible and sTable visible.
Only problem is sTable stays invisible.
What do you mean "the second form then calls sTable"? Are you opening the second form? This is not clear what you are doing at this point. How are you ensuring that both forms are indeed open? If not, there is no way for this code to work because making a form visible assumes that it is open already.

Edit: I see you add more code. What is sForm? that variable is not defined.
 
Last edited:
Looking at the logic, it says "If the form is loaded and not visible, make it visible. Refresh it and alter the contents of a control." But your narrative says you are "calling" the form and that the caller makes itself not visible. Obviously there is still more to the code because nothing in this sequence can be said to "call" the form. You can "call UP" a form by launching it (which you do with your DoCmd.OpenForm actions) but a form is not completely like a subroutine. There is no form entry point. So can you clarify your intent to "call" a form?

Opening a form - unless it is a pop-up or has other properties such as "Modal" that would grant it immediate focus and control - doesn't mean that the form is going to activate right away. It might run the _Open and _Load code but until it runs _Activate it isn't going to do anything else. The simple form you used for DoCmd.OpenForm didn't exercise any of the "priority" options so if they are in use, that means you had to have set them outside of this code.

Assuming the now-visible form is there sharing memory with whatever was diddling it, to activate the form you must set focus to one of its controls OR make the calling form close itself, thus letting Access decide where to put focus. (Note earlier exception for Pop-Up and other "take immediate control" properties.) In the normal case, if there were only two forms active when you started this sequence and you closed the currently active form, Access would choose the only other open form (as long as it has at least one enabled control.)

Then, (this is just a nit-pick)...

There is no effective difference between the next two lines of code. The first line just takes longer to get where it is going. The .Visible property doesn't toggle when you touch it. It is either TRUE or FALSE as you last set it. If your intent was to make it true, just go ahead and make it TRUE.

Code:
If Forms(sTable).Visible = False Then Forms(sTable).Visible = True
Forms(sTable).Visible = True

But like I said, that's a nit-pick.
 
I have a form, Form1, that has a button that opens a second form, Form2. Form2 searches all tables for a genus, species match.
Form1 goes invisible after the button is clicked and Form2 is the only form visible. Form1 is still open.
Form2 is now the active form taking input from a series of comboboxes.
From a dropdown list on Form2 I can select a table to view the matches. If I select the table in Form1 the sub does all the right things. It detects that form1 is loaded and not visible so goes to the set visible true clause.but nothing happens. Were Form1 not open the sub would then open it.
If I select other than Form1 the sub dutifully opens the required form and all is good.
I added the "Refresh" but it has no effect.
The sub, as shown, does exactly what it is designed to do, it's just that "Forms(sTable).Visible = True" doesn't make the form visible.
It's difficult to put into words what the logic achieves quite easily.
 
so why not close form1 when you open form2? What is the benefit of simply hiding it?
 
Just to confirm this is meeting all the criteria, I would debug it like this and also do with doc says
Code:
If CurrentProject.AllForms(sTable).isloaded Then
    debug.print forms(stable).name & " is visible "  & forms(stable).visible
    Forms(sTable).Visible = True
    If sTable = "Multi-Search" Then Forms(sTable).txtGoto_2 = ""
 Else
 
so why not close form1 when you open form2? What is the benefit of simply hiding it?
Form1 has some 90 controls and it takes a bit of time for it to open, especially over a wireless network.. If we're going back and forth, which is often the case, waiting for the Form1 to open slows down the work flow while simply hiding it means it is instantly open when needed.
 
So potentially a lot of code in form1. Are any of the forms modal? Popup? Something that would interrupt the expected flow of the code?
 
The second, small form, is modal and popup but, as stated previously, the flow of the code through the sub is normal.
I have removed the first if statement as suggested by the DocMan but that makes no difference.
 
I added "Forms(sTable).SetFocus" after the set visible = true and it now dies it's job proerly..
I thank all who offered help and suggestions.
John
 
I have removed the first if statement as suggested by the DocMan but that makes no difference.

The only difference you WOULD see is if you had a nanosecond timer. I said it was a nit-pick.

I added "Forms(sTable).SetFocus" after the set visible = true and it now dies it's job proerly..

Yes, of course! You can't set focus to something that isn't visible.
 
The only difference you WOULD see is if you had a nanosecond timer. I said it was a nit-pick.



Yes, of course! You can't set focus to something that isn't visible.
Nit pick or no, there's no point in having redundant code.
It would also seem that just making something visible is only half the answer.
BTW I couldn't find the "Solved" button>..
 
@John Sh
I can explain how this happens, but not sure why it happens.

If I hide a form and call a pop up form, I cannot unhide the form until the Pop up closes. But if I simply close the popup then unhide it works.

This will not show the hidden form when called from the pop up
Code:
Private Sub Command1_Click()
  Forms("form1").Visible = True
  DoCmd.Close acForm, Me.Name
 End Sub

However, Simply changing the order will work
Code:
Private Sub Command1_Click()
  DoCmd.Close acForm, Me.Name
  Forms("form1").Visible = True
 End Sub

Or as you said you set focus to the form it works
Code:
Private Sub Command1_Click()
  Forms("form1").SetFocus
  Forms("form1").Visible = True
  DoCmd.Close acForm, Me.Name
End Sub
Not sure why that works too.

So my question is do you call IsOpen prior to closing the Popup? Interested if you simply reverse the order and close the PopUp first then call isOpen if it works.
 
@MajP, a question about post #17, last example. In that example, if Form1 happens to not be visible at the time (even though IsLoaded = TRUE), would that work? I didn't think you could set focus to an invisible object?


The link says "You can move the focus only to a visible control or form."
 
last example. In that example, if Form1 happens to not be visible at the time (even though IsLoaded = TRUE), would that work?
It does, but no idea why or how. I just tried it because the OP said it worked. I will send the demo to show these cases.
 
Form1 has some 90 controls and it takes a bit of time for it to open, especially over a wireless network.. If we're going back and forth, which is often the case, waiting for the Form1 to open slows down the work flow while simply hiding it means it is instantly open when needed.
That's not a good idea to be using a FE connecting to a BE over a wireless network or worse a shared application over wireless connection.
 

Users who are viewing this thread

Back
Top Bottom