Me.Visible = False is Not Working Correctly (1 Viewer)

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
I'm both hoping and not hoping this is simple! LOL

I am using code from @isladogs that hides the Access application window. I presume that's the source of the irregularity, but, it could just be me! Edit: Not that Colin's code is at fault, but that it's doing something that I need to work around in order to hide my form.

Here is the Form Open Code:
Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrHandler

'Set the form size in inches, 1440 is the TWIPS per inch
Me.InsideWidth = 10 * 1440
Me.InsideHeight = 8.25 * 1440
'ReSizeForm Me
Exit Sub
   
ExitHandler:
'Some code to run if necessary after error in the future.
Exit Sub

ErrHandler:
Call ErrProcessor
Resume ExitHandler
   
End Sub

Here's the Form Load Code:
Code:
Private Sub Form_Load()
On Error GoTo ErrHandler

Select Case Me.OpenArgs 'Select the display mode based on the passed argument
   
    Case "AI_Show"  'show application interface
        DoCmd.Restore
       
    Case "AI_Hide"  'hide application interface
        Me.Painting = False
            'omit the ...Or WS_EX_APPWINDOW ...section to hide the taskbar icon
        SetWindowLong Me.hWnd, GWL_EXSTYLE, GetWindowLong(Me.hWnd, GWL_EXSTYLE) Or WS_EX_APPWINDOW
        ShowWindow Application.hWndAccessApp, SW_HIDE
        ShowWindow Me.hWnd, SW_SHOW
        Me.Painting = True
   
End Select

Me.RecordSource = "QryProjSummaryActive"  'Set the form recordsource.
Me.txtFormTitleHeader = "PROJECT LIST"   'Set the form name.

Exit Sub
   
ExitHandler:
Me.Painting = True  'In case of error this must be on.
Exit Sub

ErrHandler:
Call ErrProcessor
Resume ExitHandler
   
End Sub

And Here Is the Code in click event of the button that opens a subform and should hide this form so that a need query argument is kept.

Code:
Private Sub btnEdit_Click()
On Error GoTo ErrHandler

Debug.Print Me.Name
Me.Visible = False
DoCmd.OpenForm "FrmProjHours", , , , , , "AI_Hide"  'Launch Project Task Form
   
ExitHandler:
'Insert Any Code That Needs To Come After Error Handler Here
Exit Sub

ErrHandler:
Call ErrProcessor
Resume ExitHandler

End Sub

Debug.Print Me.Name returns the correct Form Name
 
Last edited:

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
I'm also 99% sure that it worked before I started cleaning up all my forms to match the current design. The 1% is because I'm not 100% sure it was originally in this click event. I THINK it was, but at this point I don't want to pound the table and say for sure it was.
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
Meaning it 100% worked (the form was hidden) but I'm not totally sure that it was implemented in this fashion in the click event.
 

isladogs

MVP / VIP
Local time
Today, 17:30
Joined
Jan 14, 2017
Messages
18,211
Shall I leave you to continue having a conversation with yourself? :giggle:
Anyway, whilst I understand something isn't working, its not obvious what the problem is from your description.

Can you upload a cut down version with just the relevant forms, modules and anything else needed like that query and underlying tables.
Remove anything confidential
Then explain clearly what should happen and what actually does happen.

BTW you don't need the Exit Sub line just above the Exit Handler. Whether or not there is an error, the Exit Handler section will close the procedure
 
Last edited:

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
You should hear me at my desk! Just ask my workmates!! Drives my wife crazy too. Other times she just points and laughs. I use to say it's only a problem if you start answering yourself back...now I answer myself back...LOL!

I'll import the various tables/forms into a dummy db and upload it. Whatever I did before worked, but I wasn't hiding the Access window on those forms at that time. Now, I'm consolidating....no worky.
 

isladogs

MVP / VIP
Local time
Today, 17:30
Joined
Jan 14, 2017
Messages
18,211
I added a BTW section just as you replied. You may have missed it

Also you do know you can't hide something that has the focus.
If I understand this correctly, set the focus to the other form by opening that first, then hide the first form
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
Without rehashing a previous conversation. I agree they aren't necessary, but my particularness likes them in there so that I don't forget to add it later if I actually end up needing it. Not all of my subroutines (as I'm seeing in testing this demo db) have been updated to my new standard either.
 

isladogs

MVP / VIP
Local time
Today, 17:30
Joined
Jan 14, 2017
Messages
18,211
OK. Posts keep crossing. I also added a sentence to the last reply.

If you include the extra Exit Sub, the code will never enter the Exit_Handler unless directed there following an error.
Duplicating code will cause you problems, not prevent them.
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
If I understand this correctly, set the focus to the other form by opening that first, then hide the first form
Aaarrggh! I'm fairly certain I've made this same mistake somewhere else and beat my head against the wall. I need a sign "Don't hide items with focus!"

Your duplication point is well taken.
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
Meaning it 100% worked (the form was hidden) but I'm not totally sure that it was implemented in this fashion in the click event.
Now I'm quoting myself! :ROFLMAO:
My brain was trying to tell me that the working code was somewhere else, probably in the open code of the next form.
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
Well, that may have been ONE of the problems but it wasn't THE problem. Placing .visible = False after the DoCmd.Open didn't work and placing Forms!ProjList.Visible = False in the Open of the new form didn't work either. Here is the demo db.
 

Attachments

  • TestDemo031221.accdb
    1.4 MB · Views: 314

isladogs

MVP / VIP
Local time
Today, 17:30
Joined
Jan 14, 2017
Messages
18,211
There's a lot of objects in the attached file.
Which form do I need to look at?
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
So sorry. I should have posted that. The main starting form is
frmOperationsDashboard
The forms in question are launched via "Project Hour Tracker"
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
The first form launched by clicking on "Project Hour Tracker" has edit buttons on each project. When the edit button (pencil) gets clicked, it should open the details of the hours for that project and hide the project list.
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
@isladogs - I apologize in advance because it REALLY feels like I'm missing something basic and stupid. Which would be par for the course today.
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
@isladogs - I hope you are having better success than I.

I've tried placing the code in various events. I've tried setting the focus to other forms before hiding the form. Nothing.
 

isladogs

MVP / VIP
Local time
Today, 17:30
Joined
Jan 14, 2017
Messages
18,211
Sorry but Its a total PITA
One of the disadvantages of hiding the application interface is that it makes troubleshooting much more difficult

How on earth are you meant to close form frmProjHours when its finished with?

Anyway, I've tried several things including:
a) reordering the code
b) adding DoEvents to give time for code to complete
c) hiding the form using DoCmd.OpenForm Me.Name,,,,,acHidden instead of Me.Visible=False

None worked reliably. I think your form frmProjList may be corrupted

I haven't looked at the code of mine you used. Hopefully its all present & correct

Anyway, I suggest the following changes as a starting point:
1. Open each form in the same specified location each time using DoCmd.MoveSize code. Make it exactly the same location for each for a better user experience. The MoveSize code can also be used to specify the form size so you can bin what you use now
2. Close form frmProjList when you open frmProjHours in btnEdit_Click: DoCmd.Close acForm, Me.Name
3. Reopen form frmProjList when you close frmProjHours.

Oh yes & please correct the spelling of Inspection on your dashboard form
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
1. The only reason I need to hide, instead of close is because of pulling a value for the query that underpins the project hours sheet. Believe me, I'm at the point of reworking THAT code/query instead.

2. I used DoCmd.MoveSize in other forms before. What are the benefits? Also, since this form is inherently moveable is there still a benefit?

3. The back arrow button is meant to take you back aka close the form.

4. Ooh...what a terrible misspell. Thanks for that!
 

isladogs

MVP / VIP
Local time
Today, 17:30
Joined
Jan 14, 2017
Messages
18,211
1. Suggest you save the required value to a global variable or tempvar then reference that in the other form.
That will allow you to close the first form without losing functionality.
2. DoCmd.MoveSize is concise. It allows you to specify both size and position in one line
3. What back arrow button? I can't see it!
 

JMongi

Active member
Local time
Today, 12:30
Joined
Jan 6, 2021
Messages
802
Thanks to @isladogs for his help. A quick summary:
1. Converted query to use tempvar. Works like a champ.
2. Converted Form Open procedures to DoCmd.MoveSize.

So an extra wrinkle. I've created a couple of global variables that store the current forms top and left position before it is closed and a new form is open. I then use these variables in the open procedure of the new form. Here is an example:

Code:
Private Sub Form_Close()
OldFormLeft = Me.WindowLeft
OldFormTop = Me.WindowTop
End Sub

Code:
Private Sub Form_Open(Cancel As Integer)

Dim Rt As Integer
Dim Dn As Integer
Dim Wd As Integer
Dim Ht As Integer

'Position and Size in TWIPS, 1440 TWIPS per inch
Rt = OldFormLeft
Dn = OldFormTop
Wd = 10 * 1440
Ht = 8.25 * 1440

DoCmd.MoveSize Rt, Dn, Wd, Ht

End Sub

It works well, except that I get a little bit of creep around the screen. What I mean is that if I cycle back and forth between two forms that should be storing "OldFormLeft" and "OldFormRight" each Close/Open cycle, the form location slowly migrates up and to the left. I'm guessing there is a bit of offset I need to account for, but I didn't know if anyone knew the exact amount (or how to find the exact amount).
 

Users who are viewing this thread

Top Bottom