ToolBar

mohammadagul

PrinceAtif
Local time
Tomorrow, 00:36
Joined
Mar 14, 2004
Messages
298
I have a Standard Toolbar in my database. There are presently three button in it.

New
Save
Close

I want to add a Print Button which should print the current record of the form. Lets says if the customers form is open and the user click this "Print" Button it should print only the current customer. Similarly the same print button should work for Suppliers and Products. if either of form are open and user click the "Print" Button , it should print the Current correspoding record of the form.

Note: Although the normal command buttons are available in the command button wizard to print and preview selected reports, but i would still insiste in using this method.

I only need somthing to start with.

Thanks
 
right click the menu bar then go to customize...

then click commands and drag the "custom" button to your menu bar. THen right click the custom button and goto properties. where it says on action put in something like =MyPrintJob()

you might wanna change the caption, name, image etc...

then make a new module and put something like this


Public Function MyPrintJob()

DoCmd.OpenReport "MyReport"

End Function


So on click of the button it runs that function... Hope this helps
 
everthing is correct except that you havvent noticed my questions. i want this function to check the opened form andthen print the report corresponding to that form.
 
Do something like,

IF [Screen].[ActiveForm].Name = "frmWhatever" then
Docmd.openreport "whatever"
End If

IF [Screen].[ActiveForm].Name = "frmWhatever2" then
Docmd.openreport "whatever2"
End If
 
Hi, Thanks you for you reponses in respect to my question. I had done as mentioned and this is what i have got now. Its working pretty well. Atleast it had removed all my command buttons that i am using in my form and now my database look really professional.

Option Compare Database
Option Explicit

Public Function PrintJob()
On Error GoTo Err_PrintJob

If [Screen].[ActiveForm].NAME = "InvoiceCredit" Then
DoCmd.OpenReport "Invoice", acPreview, , "[ManualInvoiceNo] = Forms!InvoiceCredit!ManualInvoiceNo"
End If

If [Screen].[ActiveForm].NAME = "Customers" Then
DoCmd.OpenReport "Customer Detailed Report", acViewPreview, , "[ID] = Forms!Customers!ID"
End If

Exit_PrintJob:
DoCmd.SetWarnings True
Exit Function

Err_PrintJob:
If err = 2475 Then 'The command or action 'Delete Record' isn't available now
DoCmd.SetWarnings True
Exit Function
Else
MsgBox err.Number & " - " & err.Description
Resume Exit_PrintJob
End If
End Function

Well now my i would like to knwo if this code is correct. To me it does not give any errors but still i want advice from experts. specially for the error handling.

Hope to Receive quick reponse as always.

Thanks
 

Users who are viewing this thread

Back
Top Bottom