Go Back   Access World Forums > Microsoft Access Discussion > Reports

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 09-14-2019, 06:07 AM   #16
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,401
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Run code before close report

Code:
Select Case [Forms]![FormLogin].[txtDienstID]
       Case 1, 2, 5, 8
            CurrentDb.Properties("AllowShortcutMenus") = True
       Case Else
            CurrentDb.Properties("AllowShortcutMenus") = False
       End Select

__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
The Following User Says Thank You to arnelgp For This Useful Post:
scallebe (09-14-2019)
Old 09-14-2019, 06:58 AM   #17
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,401
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Run code before close report

you need to save [Forms]![FomLogin]![txtDienstID] to a public variable, so you can access them in the report.
after logging in:
Code:
Tempvars.Add "allow_shortcut", (Instr(1, ",1,2,5,8", "," & [Forms]![FomLogin]![txtDienstID] & ",") > 0)
on each report, check this variable on its, Open event:
Code:
Private Sub Report_Open(Cancel As Integer)
If [Tempvars]![allow_shortcut] = False Then
    Me.ShortcutMenuBar = "menu_print"
End If
End Sub
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
The Following User Says Thank You to arnelgp For This Useful Post:
scallebe (09-14-2019)
Old 09-14-2019, 07:10 AM   #18
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Run code before close report

arnelgp,

I realy appreciate what you do, fantastic!!!


With you last code you disable all the shortcutmenu's for all users in forms and reports. But now the users can not print any report because I disabled the ribbon…

That's why your code for small shortcutmenu's is so perfect.

In the beginning you created a shortcutmenu with : Print & Close (I called it print_menu2)

Later you created a shortcutmenu with Print, Close and DesignView (it's called print_menu)

Is it possible to give/activate for the users "print_menu2" and the admins (1,2,5,8) "print_menu"

In this way the users can print or close the report and the admin can also go to the design of the report.


Thanks a lot

Greetz

Pascal

scallebe is offline   Reply With Quote
Old 09-14-2019, 07:12 AM   #19
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Run code before close report

Sorry,

I didn't see you last post...
scallebe is offline   Reply With Quote
Old 09-14-2019, 07:20 AM   #20
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Run code before close report

arnelgp,

So the first line of code (Tempvars.Add……etc.) I put in in my LoginForm?

Because I don't know what you mean with public variable… (sorry)


Thanks again

Greetz

Pascal
scallebe is offline   Reply With Quote
Old 09-14-2019, 07:36 AM   #21
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,401
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Run code before close report

you put it here:
Code:
Select Case [Forms]![FormLogin].[txtDienstID]
       Case 1, 2, 5, 8
            CurrentDb.Properties("AllowShortcutMenus") = True
       Case Else
            CurrentDb.Properties("AllowShortcutMenus") = False
       End Select

Tempvars.Add "allow_shortcut", (Instr(1, ",1,2,5,8", "," & [Forms]![FomLogin]![txtDienstID] & ",") > 0)
now on open event of all Reports:
Code:
Private Sub Report_Open(Cancel As Integer)
If [Tempvars]![allow_shortcut] = False Then
   'not admins
    Me.ShortcutMenuBar = "menu_print2"
Else
    Me.ShortcutMenuBar = "menu_print"
End If
End Sub
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 09-14-2019, 07:45 AM   #22
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,401
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Run code before close report

or to make it simple:
Code:
Select Case [Forms]![FormLogin].[txtDienstID]
       Case 1, 2, 5, 8
            CurrentDb.Properties("AllowShortcutMenus") = True
       Case Else
            CurrentDb.Properties("AllowShortcutMenus") = False
       End Select
Code:
Private Sub Report_Open(Cancel As Integer)
If (CurrentDb.Properties("AllowShortcutMenus")) = True Then
   'admins
    Me.ShortcutMenuBar = "menu_print"
Else
    Me.ShortcutMenuBar = "menu_print2"
End If
End Sub

__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 09-14-2019, 07:58 AM   #23
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Run code before close report

arnelgp,

That's where I'm a little confused,

Do I put in the Loginform or in a module?
scallebe is offline   Reply With Quote
Old 09-14-2019, 08:31 AM   #24
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Run code before close report

Arnelgp,

To enable or disable the shortcutmenu for all forms the code is placed in every on open event of the form. And only the forms who are available for users. Not in the Admin forms.

So where do I place the code :

Code:
Select Case [Forms]![FormLogin].[txtDienstID]
       Case 1, 2, 5, 8
            CurrentDb.Properties("AllowShortcutMenus") = True
       Case Else
            CurrentDb.Properties("AllowShortcutMenus") = False
       End Select
I think because you set CurrentDB.properties…. it goes in a module. But I don't know how.

The report Open event that I understand…

Thank you for your patience

Greetz

Pascal
scallebe is offline   Reply With Quote
Old 09-14-2019, 08:43 AM   #25
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,401
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Run code before close report

for code in post #24, you put it same as in post #13.
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 09-14-2019, 09:09 AM   #26
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Run code before close report

arnelgp,

The code in post #13 is in all forms (for users) in the on open event to enable or disable the shortcutmenu in the forms.

Now I want to use the print_menu & print_menu2 in the repports.

I can't believe that's the intention to put the code in post #24 in the on open event of all forms (for users)

Or am I wrong?

Thanks
scallebe is offline   Reply With Quote
Old 09-14-2019, 09:21 AM   #27
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,401
Thanks: 68
Thanked 2,701 Times in 2,586 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Run code before close report

do you have code for your login form (FormLogin)? what is txtDienstID, is it a textbox?
if it is add code to its AfterUpdate and put the code there:
Code:
Private Sub txtDienstID_AfterUpdate()
Select Case Me![txtDienstID]
       Case 1, 2, 5, 8
            CurrentDb.Properties("AllowShortcutMenus") = True
       Case Else
            CurrentDb.Properties("AllowShortcutMenus") = False
       End Select
End Sub
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
The Following User Says Thank You to arnelgp For This Useful Post:
scallebe (09-14-2019)
Old 09-14-2019, 09:54 AM   #28
scallebe
Newly Registered User
 
Join Date: Mar 2018
Posts: 51
Thanks: 29
Thanked 1 Time in 1 Post
scallebe is on a distinguished road
Re: Run code before close report

arnelgp,

I didn't work in the afterupdate event of the textbox.

My LoginForm stays open but hidden after input password. For various reasons. In many cases I refer to certain data in that form... one of them is DienstID...

So I put the code in the FormLogin load event and the other part in the report open event and….. it works perfect....

Finally

Thank you so much, it was a productive day today

Enjoy the rest of the weekend

Greetz

Pascal

scallebe is offline   Reply With Quote
The Following User Says Thank You to scallebe For This Useful Post:
arnelgp (09-14-2019)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Close Code ECEK Forms 6 11-18-2016 04:24 AM
Open recordset on report open, close on report close bulrush Reports 2 03-14-2011 09:48 AM
Close report code not working jd_boss_hogg Modules & VBA 2 09-20-2009 11:22 PM
Code to close a db? Dudley Modules & VBA 4 09-02-2008 02:22 PM
close the code? miki Forms 1 10-28-2001 09:17 PM




All times are GMT -8. The time now is 02:18 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World