Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Printing?

Status
Not open for further replies.

cranebill

IS-IT--Management
Jan 4, 2002
1,113
US
Hi,
Yet again another task i do not know how to do so any help would be greatly appreciated. I have a database set up with user permissions etc.. I would like to do one of two things.. either disable printing for certain users or if all else fails disable printing all together. Has anyone ever done anything like this before, if so any help would so greatly be appreciated.

Thank you,
Bill
 
Hi

How clever are your users?, firts thought would be to create a custom menu bar which omitted the File\Print option, but if they are smart enough to know about Cntrl-P, that is no good.

Have to think a bit more about this one.

Regards

Ken Reay
Freelance Developer
kenneth.reay@talk21.com
 
Well they do not know about CTRL-P but they can still use the file print option unless it can be taken out of there also.. that may actually work but it would also mean unless others knew about CTRL-P then the people that needed to print would not be able to. and if i tell them then of course it will leak lol

Thankx Bill
 
Hi Bill

Yes, but if you make two custome menus, one with File\Print and One without, then display the appropriate menubar, depending on the user ID, how about that

Regards
Ken Reay
Freelance Developer
kenneth.reay@talk21.com
 
That would work, now the question being how to set it up to do that lol still a little out of my league.
 
Hi

That would take a lot of explaining, but sample code to point you in right direction is given below:

Note it is not complete, just an example

Sub bisEnableMenuControls(strFormType As String)
' Comments : Sub to enable CommandBarControls dependent upon Application Status
' (type of form open)
'
' --------------------------------------------------------

Dim cmdEditMenu As CommandBar
Dim strMenuToEdit As String

strMenuToEdit = "mnubisMenu"

On Error GoTo PROC_ERR

If bisCommandBarExists(strMenuToEdit) Then

Set cmdEditMenu = CommandBars(strMenuToEdit)
cmdEditMenu.Visible = True

'Enable all controls that may have been disabled before.
cmdEditMenu.Controls("Edit").Visible = True
cmdEditMenu.Controls("File").CommandBar.Controls("Close").Visible = True
cmdEditMenu.Controls("File").CommandBar.Controls("Print").Visible = True

'disable controls not required
Select Case strFormType

Case "SwitchBoard"
cmdEditMenu.Controls("Edit").Visible = False
cmdEditMenu.Controls("File").CommandBar.Controls("Close").Visible = False
cmdEditMenu.Controls("File").CommandBar.Controls("Page Setup").Visible = False
cmdEditMenu.Controls("File").CommandBar.Controls("Print").Visible = False
cmdEditMenu.Controls("File").CommandBar.Controls("Send").Visible = False
cmdEditMenu.Controls("File").CommandBar.Controls("Save As Excel").Visible = False

Case "SimpleForm"
cmdEditMenu.Controls("Edit").Visible = False
cmdEditMenu.Controls("File").CommandBar.Controls("Print").Visible = False
cmdEditMenu.Controls("File").CommandBar.Controls("Page Setup").Visible = False
cmdEditMenu.Controls("File").CommandBar.Controls("Send").Visible = False
cmdEditMenu.Controls("File").CommandBar.Controls("Save As Excel").Visible = False

Case "StandardForm"
cmdEditMenu.Controls("File").CommandBar.Controls("Print").Visible = False

Case "Report"
cmdEditMenu.Controls("Edit").Visible = False
cmdEditMenu.Controls("File").CommandBar.Controls("Page Setup").Visible = True
cmdEditMenu.Controls("File").CommandBar.Controls("Send").Visible = True
cmdEditMenu.Controls("File").CommandBar.Controls("Save As Excel").Visible = True

End Select
End If

Exit Sub

PROC_ERR:
MsgBox "The following error occured: " & Error$
Resume Next

End Sub Ken Reay
Freelance Developer
kenneth.reay@talk21.com
 
If you need menu click control, just subclass the commandbar using a class module, and you can override the default functionality of the "&Print..." control, or cancel it altogether.

In a class module (clsPrintHandler), add:

Public WithEvents cbCtlPrint as Office.CommandBarButton


Using 'WithEvents' allows you to trap the click event for this menu item.


In the class initialize event, add:

Private Sub Class_Initialize()
Set cbCtlPrint = CommandBars("File").Controls("Print...")
End Sub

Your click event looks like this:

Private Sub cbCtlPrint_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
If <condition not met> Then
CancelDefault = True
End IF
End Sub

Then you just need to declare a global variable in a standard module:

Public gcbCtlPrint as clsPrintHandler

The final step is to initialize the class, which should be done in your startup form or switchboard load event:

Private Sub Form_Load()
Set gcbCtlPrint = New clsPrintHandler
' Other stuff
End Sub

Once you get this set up, the click event will fire any time someone clicks print, and you can check their login before allowing the print. Of course, you'll have to make sure any other print menus and toolbar buttons are handled as well.

Make sure to create an 'Autokeys' macro to trap the Ctrl-P shortcut as well.

Good Luck,


VBSlammer
redinvader3walking.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top