Trying to implement the SetAccessWindow code (1 Viewer)

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
Colin, (or anyone else that is familiar with this)

I am trying to use your code in teh SetAccessWindow database sample found here: https://www.access-programmers.co.uk/forums/showthread.php?t=293584 to only leave up my main form (frm_main). I do not need command buttons to make this happen... I just wanted it to work straight away.

In the code for frm_home I added this at the top:
Code:
Option Compare Database
Option Explicit

Dim blnShowWindow As Boolean
Dim blnShowRibbon As Boolean
Dim blnShowNavPane As Boolean
Dim FEVersion As Variant

I added this to the Form_Open:
Code:
HideRibbon
HideNavigationPane
ReSizeForm Me

and this to the Form_Load:
Code:
SetAccessWindow (SW_SHOWMINIMIZED)

Of course I imported all of the modules but I didn't add any click event code anywhere.

when I open my database... the access window is still open... I am sure I am doing something wrong.

Any ideas what I am missing?
 

isladogs

MVP / VIP
Local time
Today, 07:08
Joined
Jan 14, 2017
Messages
18,216
Does frmMain run at startup?
Make sure your form properties has Popup = Yes

In Access options, make sure Show Navigation Pane is unticked

You may not need HideRibbon & HideNavigationPane as you are (trying to) hide the whole application interface. If you do need them as well, move to Form_Load

The ResizeForm_Me is used to resize the form for different resolutions. Its not needed for this purpose though feel free to use it as well

HTH
 

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
Does frmMain run at startup?
Make sure your form properties has Popup = Yes

In Access options, make sure Show Navigation Pane is unticked

You may not need HideRibbon & HideNavigationPane as you are (trying to) hide the whole application interface. If you do need them as well, move to Form_Load

The ResizeForm_Me is used to resize the form for different resolutions. Its not needed for this purpose though feel free to use it as well

HTH

The frm_home is set to open at startup but has code in it to open the login form first then show the frm_home after that.

I set the frm_home to be a popup and navigation pane is unchecked.

This time it opened as a popup form but the application window is still up behind it (on the screen) and it has a window border around it (the frm_home) and is draggable to move or resize... yours in the sample database does not do that.

*Edit*

Only sometimes does it leave the application window up on the screen. Rookie mistake on the form border... changed the border property and auto center property but still the app window issue.
 
Last edited:

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
I cannot figure out why it randomly leaves the app window open in the background... sometimes it works... sometimes it doesn't.

One more thing about this modification... I notice that if the end user has their access app maximized... the frm_home is also maximized instead of just the size of the form like in your sample db.

This is kinda the point of why I was trying to use this so it forces the window size.

Is it possible to make that happen regardless of how they use access for this db?

On a lighter note... once I put this code in my db...DRAMATIC INCREASE IN OPENING SPEED!!!

Related to the other very long thread about that subject... somehow this fixed that.

Awesome so far.
 

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
I moved the calls from frm_home to frm_loginform and that seems to have solved it.

My other question regarding the forced size on open remains though.
 

isladogs

MVP / VIP
Local time
Today, 07:08
Joined
Jan 14, 2017
Messages
18,216
Try adding the line DoCmd.Restore in the form load event

Also make sure you use Overlapping Windows rather than Tabbed Documents in Access Options
 
Last edited:

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
Try adding the line DoCmd.Restore in the form load event

Also make sure you use Overlapping Windows rather than Tabbed Documents in Access Options

Ok... I changed the option to overlapping instead of tabbed and that caused a whole new issue.

On my frm_labtestinput I have 3 subforms and using the grow and shrink code discussed in another thread. When using overlapping rather than tabbed... when the subform displays on the frm_labtestinput it is off the screen at the bottom and the fields cannot be seen or used.


As it turns out I do not need to use overlapping after all.

I also used the DoCmd.Restore and it was not necessary. After working on removing the borders and scroll bars from the frm_home it seems to have solved the issue when they had their access app maximized.

However... there is always a however... my reports are now screwed up even though I have changed no settings in them. When I click on a report it shows up like this:

Instead of the size I saved it as the last time I had it open.

If I drag the bottom of it down to view it I notice the scroll bar is only present until I get about half way across the first records displayed like this:


If I drag the bottom further down to view the report, the scroll bars disappear completely like this:


This all happened after I removed the borders and scroll bars from the frm_loginform form and the frm_home to get rid of the gray bar at the bottom of them.

This is weird... any ideas what to do to correct this without having to put all the borders and scroll bars back in those 2 forms?

Should this have been in another forum?
 

Attachments

  • Capture3.JPG
    Capture3.JPG
    32.5 KB · Views: 343
  • Capture.JPG
    Capture.JPG
    12.5 KB · Views: 339
  • Capture1.JPG
    Capture1.JPG
    18.4 KB · Views: 340
  • Capture2.JPG
    Capture2.JPG
    45.3 KB · Views: 349
Last edited:

isladogs

MVP / VIP
Local time
Today, 07:08
Joined
Jan 14, 2017
Messages
18,216
OK sorry about that.
Of course you do ALWAYS make a backup before doing design changes ... don't you? NO?

When you need to resize something, better to do so then save whilst in design view.

Don't forget to backup first !
 

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
OK sorry about that.
Of course you do ALWAYS make a backup before doing design changes ... don't you? NO?

When you need to resize something, better to do so then save whilst in design view.

Don't forget to backup first !

Nothing to be sorry about... I always make backups and the overlap issue was easy to reverse.

The issue with the reports is not related to the overlap thing. Could it be related to the SetAccessWindow (SW_SHOWMINIMIZED) in the code in the frm_loginform?

Should I try to address the report thing in the reports forum?
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 07:08
Joined
Jan 14, 2017
Messages
18,216
No Re: Trying to implement the SetAccessWindow code

Nothing to be sorry about... I always make backups and the overlap issue was easy to reverse.

The issue with the reports is not related to the overlap thing. Could it be related to the SetAccessWindow (SW_SHOWMINIMIZED) in the code in the frm_loginform?

Should I try to address the report thing in the reports forum?

Answering on my phone so unable to check code.
I don't see why it would be related.
Also, I thought the issue only started when you changed from tabbed documents.
If you go back to my example database, that includes a report. Have a look at that part and see if it helps
 

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
It appears that it is related. I saw a few other posts on other sites regarding the exact same issue while using the showminimized coding. However no viable solution were available that I could find.

I had thought that it was related to the borders and scrollbars but it was not as I tested backing out the changes and re-testing.

So that being said... the solutions that were presented by others on other sites were to add DoCmd.Maximize in the On Open of the report then DoCmd.Restore in the On Close but this caused a 2501 run-time error in this code of my frm_newreportcenter
Code:
Option Compare Database

Private Sub cmdGenerateReport_Click()

    If Me.cboReports & "" <> "" Then
        [COLOR="Red"]DoCmd.OpenReport cboReports, acViewReport, , IIf(IsNull(Me.cboFacility), "", "Facility='" & Me.cboFacility & "'")[/COLOR]
    Else
     MsgBox ("You Must First Select a Report To Print!")
     cboReports.SetFocus
   End If

   cboReports = ""
End Sub
which is the button code for my report generation filter (also discussed in another thread).

I also saw suggested to use Application.RunCommand acCmdAppMinimize instead of SetAccessWindow (SW_SHOWMINIMIZED) which I tried but the result was the same.
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 07:08
Joined
Jan 14, 2017
Messages
18,216
I've used similar code on numerous databases and don't recall it causing issues with reports.
As before I'm not at my computer and won't be able to check my code for several hours.
Have you looked to see if there is anything I've done to make it work without problems for me?

It would save both you and those answering if you added Option Explicit on each code module and error handling in each procedure.

Error 2501 occurs when you start an action then cancel it. You need to determine why that occurs here.

Try replacing your code with

Code:
Option Compare Database
Option Explicit

Private Sub cmdGenerateReport_Click()

    If Nz(Me.cboReports,"") <> "" Then
        DoCmd.OpenReport cboReports, acViewReport, , IIf(Nz(Me.cboFacility,"")<>"", "Facility='" & Me.cboFacility & "'","")
    Else
     MsgBox "You Must First Select a Report To Print!"
     Me.cboReports.SetFocus
   End If

   Me.cboReports = "" 'if necessary try omitting this line and adding it in a different procedure
End Sub

Add error handling
 

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
Colin... as usual I appreciate all of the help you give me.

In this case it was something pretty stupid simple.

I set the Auto Resize property to no on all of the reports and that fixed the problem.
 

isladogs

MVP / VIP
Local time
Today, 07:08
Joined
Jan 14, 2017
Messages
18,216
Ha! Glad you got it working.

Just to clarify, am I correct in saying the issue was nothing to do with my code.

What about error 2501? Is that also now fixed?
 

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
Just to clarify, am I correct in saying the issue was nothing to do with my code

Technically no... it does exactly what it is supposed to do. I just needed to tweak the properties of the reports to work the way I wanted them to along with the code.

What about error 2501? Is that also now fixed?

This does not happen anymore. After removing the code solutions I saw on the other sites the issue went away.

It appears there is only one more thing I am trying to work out now related to the showminimized code.

I have 2 labels on my login form that are clickable... one opens a form for users to register and the other opens the form for current users to reset their forgotten password.

As these do not conform to the login form actions like the username, password and command button to login and take you to the frm_home... those 2 previously mentioned forms do not comply with the showminimized code.

They want to open maximized. I tried setting them to open acDialog but in doing that it caused them to act funny when submitting their information or canceling via the command buttons.

If I went through the registration process and clicked the command button to register it would do so and then close the form but instead of going back to the login form it would popup the registration form again and the cancel button would have to be clicked to get back to the login form.

On the other side of that if I clicked the label to open the registration form and then clicked the cancel button it would popup the registration form again and then have to cancel again to get back to the login form.

Ugh
 
Last edited:

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
So... to elaborate on my last question above... here is a screenshot of the login form (frm_loginform)


The circled label links are the ones I am talking about.

Just talking about the register as new user label link. I have an embedded macro for that one.


When I click on it the database application window comes back up insead of staying minimized.
**Removed image because it was so large

I tried using vba instead of an embedded macro but that didn't work either.

Any words of wisdom to help solve this one for me?
 

Attachments

  • Capture.JPG
    Capture.JPG
    29.1 KB · Views: 270
  • Capture1.jpg
    Capture1.jpg
    84.6 KB · Views: 88
  • Capture2.JPG
    Capture2.JPG
    23.3 KB · Views: 276
Last edited:

isladogs

MVP / VIP
Local time
Today, 07:08
Joined
Jan 14, 2017
Messages
18,216
This may be a side effect of using popup/modal forms.
Try repeating the code used to hide the application interface when you open the new form

For info, I never use embedded macros as VBA is more powerful. I also prefer to have all code easily visible.
 

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
This may be a side effect of using popup/modal forms.
Try repeating the code used to hide the application interface when you open the new form

For info, I never use embedded macros as VBA is more powerful. I also prefer to have all code easily visible.

I tried that before posting about it. I added
Code:
Option Compare Database
Option Explicit

Private blnGood As Boolean
Dim blnShowWindow As Boolean

Private Sub Form_Load()
  SetAccessWindow (SW_SHOWMINIMIZED)
End Sub
in the module for the frm_registrationform but it didn't stop the access app from opening back up. It only minimizes again if I cancel out of the form or fill it out and submit it.
 

isladogs

MVP / VIP
Local time
Today, 07:08
Joined
Jan 14, 2017
Messages
18,216
It would really help if you stated what you have tried before posting!

Have another look at the attached file.
In particular review the code used with the last button on the main form: 'Open Form Query'

Both the main form frmStart & frmFormQuery are popup forms.
The application interface remains hidden as you switch from one form to the other.

By contrast the third form frmAccessErrorCodes is NOT a popup form.
when you click the 'Open Form' button to open that form, the application interface is displayed.
 

Attachments

  • SetWindows - v2.zip
    327.4 KB · Views: 32

psyc0tic1

Access Moron
Local time
Today, 01:08
Joined
Jul 10, 2017
Messages
360
It would really help if you stated what you have tried before posting!

Have another look at the attached file.
In particular review the code used with the last button on the main form: 'Open Form Query'

Both the main form frmStart & frmFormQuery are popup forms.
The application interface remains hidden as you switch from one form to the other.

By contrast the third form frmAccessErrorCodes is NOT a popup form.
when you click the 'Open Form' button to open that form, the application interface is displayed.

I reviewed you code like you said and I copied the code from frmFormQuery on open and on load events into my frm_registrationform which now looks like this:
Code:
Option Compare Database
Option Explicit

Private blnGood As Boolean

Private Sub Form_Load()

On Error GoTo Err_Handler

    SetAccessWindow (SW_SHOWMINIMIZED)

    DoCmd.Restore
    
Exit_Handler:
    Exit Sub

Err_Handler:
    strProc = Application.VBE.ActiveCodePane.CodeModule.ProcOfLine(Application.VBE.ActiveCodePane.TopLine, 0)
    MsgBox "Error " & Err.Number & " in " & strProc & " procedure : " & Err.Description
    Resume Exit_Handler
    
End Sub

Private Sub Form_Open(Cancel As Integer)

On Error GoTo Err_Handler

    ReSizeForm Me
    
Exit_Handler:
    Exit Sub

Err_Handler:
    strProc = Application.VBE.ActiveCodePane.CodeModule.ProcOfLine(Application.VBE.ActiveCodePane.TopLine, 0)
    MsgBox "Error " & Err.Number & " in " & strProc & " procedure : " & Err.Description
    Resume Exit_Handler
  
End Sub

and I copied your code from frmStart into my login form code which now looks like this:
Code:
Option Compare Database
Option Explicit

Dim blnShowWindow As Boolean

Private Sub Form_Load()
  CheckFrontEnd.CheckFrontEnd
  SetAccessWindow (SW_SHOWMINIMIZED)
  blnShowWindow = False
End Sub

Same results as before.

I did the decompile and recompile using Option Explicit in all of my code... only had a couple of variables to define which was good. Compacted and repaired of course.

There are only minor differences between my frm_registrationform and your frmFormQuery.

Under "Format"
#1 yours is Continuous Form mine is Single Form
#2 yours is Allow Layout View - yes mine is no
#3 yours is Auto Resize - yes mine is no
#4 yours is Border Style - None mine is sizeable
#5 yours is Navigation Buttons - Yes mine is no
#6 yours is Scrollbars - Both mine is none
#7 yours is Control box - Yes mine is no
#8 yours is Close button - Yes mine is no
#9 yours is Min-Max buttons - Both enabled mine is none

Under "Data"
#1 yours is Record Source is a query mine is a table
#2 yours is Data Entry - No mine is yes
 

Users who are viewing this thread

Top Bottom