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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable printing of forms. 1

Status
Not open for further replies.

mauricionava

Programmer
Jul 8, 2005
209
US
Hello, is there a way to disable the printing of the forms? I have over 1500 records and sometimes by mistake users go to File/Print and print all records in the form view.

How can I disable the option of printing the form view but leave enable the printing of reports?

Thanks!
 
How are ya mauricionava . . .
mauricionava said:
[blue]How can I disable the option of printing the form view but leave enable the printing of reports?[/blue]
You take control of the [blue]Enabled property[/blue] for the [blue]Print/Print Preview[/blue] buttons.
[ol][li]Since were talking commandbars here you'll have to install a library (if not already). So in any code module from the menubar select [blue]Tools[/blue] - [blue]References[/blue]. In the list your looking for [purple]Microsoft Office x.x Object Library[/purple]. Put a check in the box for the highest version you have and click OK.[/li]
[li]In a [blue]module[/blue] in the [blue]modules window[/blue] copy/paste the following routine:
Code:
[blue]Public Sub AllowPrint(Ctl As Boolean)
   Dim MainBar As CommandBar, subBar, flgView As Boolean
   
   Set MainBar = CommandBars("Menu Bar")
   Set subBar = MainBar.Controls("File")
   
   subBar.Controls("Print...").Enabled = Ctl
   subBar.Controls("Print Preview").Enabled = Ctl
   
   Set subBar = Nothing
   Set MainBar = Nothing
   
End Sub[/blue]
[/li][/ol]
Now your set.

In the [blue]On Open[/blue] event of each form you would certainly have . . .
Code:
[blue]   Call AllowPrint([purple][b]False[/b][/purple])[/blue]
. . . and in the [blue]On Open/On Close[/blue] events of reports you respectively pass [purple]True/false[/purple]. Other than that use of the routine is at your discretion.

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
And this to prevent the shortcut "CTRL+P"
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyP And vbKeyControl Then
        MsgBox "Print disabled on form, Use reports to print"
        KeyCode = 0
    End If
End Sub
Add the same for subforms too. Set KeyPreview=Yes

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
Please ignore that post. Not wroking well.

________________________________________________________
Zameer Abdulla
Help to find Missing people
Sharp acids corrode their own containers.
 
TheAceMan1, thanks for the codes.

When I open the form and I go to File/Print I see it is disabled, when I open a report after I put the code Call AllowPrint(True) in the On Open event I see that the Print menu is enabled but when I go back to the form I see that the Print option is available too. How is that?

Thanks
 
Put the code in the GotFocus event procedure too ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
mauricionava said:
[blue] . . . [purple]when I go back to the form I see that the Print option is available too. How is that?[/purple][/blue]
When switching back to form from report or vice versa [blue]there's nothing to change the current state of the disabled properties proper![/blue]

I simply tested that the routine works . . . I didn't test logical switching as you've presented it! . . . but have no fear! . . . Perform the following:
[ol][li]Delete any code given for the [blue]On Open[/blue] event of forms and reports.[/li]
[li]In the [blue]On Activate[/blue] event of forms . . .
Code:
[blue]   Call AllowPrint([b]False[/b])[/blue]
[/li]
[li] . . . and the [blue]On Activate[/blue] event of reports:
Code:
[blue]   Call AllowPrint([b]True[/b])[/blue]
[/li][/ol]
Do your testing and let me know. I expect this will cover the bases!

BTW: Have a look at FAQ219-2884 [thumbsup2]. I'm sure you'll find some sentences important to us tiptsters!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Works awesome!

Thank you very much, this is going to save a lot of trees!
 
And how can I take it all off? Because it affected all of my forms and reports!

 
That file where I put the code is in a server where some users go that location and open the file from the server and now all computers have the File/Print option disabled in every access database, not only the one I put the code in but all access applications.

Is there a way to fix that?
 
mauricionava said:
[blue]That file where I put the code is in a server . . . [purple]now all computers have the File/Print option disabled in every access database[/purple] . . .[/blue]
If my read is correct . . . you put the code in an access DB on the server and that DB is not split (front/back end). [blue]Is this correct?[/blue]

Calvin.gif
See Ya! . . . . . .
 
mauricionava . . .

Scratch my last post. Your correct as were disabling a part of access system menu's. You'll need to make your own in this case (you can duplicate the file menu).

Calvin.gif
See Ya! . . . . . .
 
I also have the same problem that mauricionava had."That file where I put the code is in a server where some users go that location and open the file from the server and now all computers have the File/Print option disabled in every access database, not only the one I put the code in but all access applications.

Is there a way to fix that?"

I don,t understand your reply. Is there a way to fix it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top