<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener("load", function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <iframe src="http://www.blogger.com/navbar.g?targetBlogID=34083602&amp;blogName=LEARN+MS-ACCESS+TIPS+AND+TRICKS&amp;publishMode=PUBLISH_MODE_FTP&amp;navbarType=BLUE&amp;layoutType=CLASSIC&amp;searchRoot=http%3A%2F%2Fblogsearch.google.com%2F&amp;blogLocale=en_US&amp;homepageUrl=http%3A%2F%2Fwww.msaccesstips.com%2F" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="30px" width="100%" id="navbar-iframe" allowtransparency="true" title="Blogger Navigation and Search"></iframe> <div></div>
www.msaccesstips.com

LEARN MS-ACCESS TIPS AND TRICKS


International Response Fund

LEARN MS-ACCESS TIPS AND TRICKS

↑ Grab this Headline Animator

Your Ad Here
Friday, June 12, 2009

Network And Print Page Setup-2

We have seen in the earlier Article how to change Paper Size and Page Orientation of MS-Access Reports automatically through program for any Printer on the Network. We have copied PrtDevMode Property Values into Memory; modified them to match the Paper Size and Page Orientation of the Report and updated them back into the Report Page Settings before printing it on the default Printer installed on the User's Machine.


We are going to perform a similar exercise to change the Margin Settings of MS-Access Report through program. This time we have to work with PrtMip Property of the Report to change the Margin Values.


The procedure is almost same as of the previous example. The steps taken in the Program is as follows:


  • Open the Report in Design View.

  • Copy the PrtMip Property Values of the Report into a 28 Bytes long String Variable and move it into a redefined structured data area for modification.

  • Change the required Margin Values in Memory.

  • Update them back into the Report’s PrtMip Property.

  • Save the Report with the changes and open it in Print Preview.



So let us start.



  1. Open one of your Databases with Reports in it.

  2. Display the Visual Basic Editing Window (Alt+Fll).

  3. Insert (Insert - - > Module) a new Standard Module (Global Module).

  4. Copy and paste the following Code into the new Module and save it.



  5. Private Type str_PRTMIP
    strRGB As String * 28
    End Type

    Private Type type_PRTMIP
    xLeftMargin As Long
    yTopMargin As Long
    xRightMargin As Long
    yBotMargin As Long
    fDataOnly As Long
    xWidth As Long
    yHeight As Long
    fDefaultSize As Long
    cxColumns As Long
    yColumnSpacing As Long
    xRowSpacing As Long
    rItemLayout As Long
    fFastPrint As Long
    fDatasheet As Long
    End Type

    Public Sub SetMargins(ByVal strName As String)

    Dim PrtMipString As str_PRTMIP
    Dim PM As type_PRTMIP
    Dim rpt As Report
    Const TWIPS As Long = 1440
    ' Open the report.
    DoCmd.OpenReport strName, acDesign
    Set rpt = Reports(strName)
    PrtMipString.strRGB = rpt.PrtMip
    LSet PM = PrtMipString

    ' Set margins.
    PM.xLeftMargin = 0.75 * TWIPS
    PM.yTopMargin = 0.5 * TWIPS
    PM.xRightMargin = 0.5 * TWIPS
    PM.yBotMargin = 0.5 * TWIPS

    ' Update property.
    LSet PrtMipString = PM
    rpt.PrtMip = PrtMipString.strRGB

    DoCmd.Close acReport, strName, acSaveYes
    DoCmd.OpenReport strName, acViewPreview

    Set rpt = Nothing

    End Sub




  6. Open one of your existing Reports in Design View.

  7. Select File - ->Page Setup- - > Margins.

  8. Change all four sides (Left, Right, Top and Bottom) of the Margin settings to 1 Inch.

  9. Save and Close the Report.

  10. Open the Main Switchboard Form of your Application or create a new Form.

  11. Create a new Command Button on the Form.

  12. While the Command Button is in selected state, display the Property Sheet (View - ->Properties).

  13. Change the Name Property Value to cmdPreview and change the Caption Property Value to Print Preview.

  14. Display the Code Module of the Form (View - -> Code).

  15. Copy and paste the following lines into the Code Module of the Form.


  16. Private Sub cmdPreview_Click()
    SetMargins "MyReport"
    End Sub

  17. Replace the name MyReport with your own Report Name.

  18. Save and close the Form.

  19. Open the Form in normal view and Click on the Command Button to run the Program and change all four margins of the Report to new values and to open the Report in Print Preview.


Close the Report and open it again in Design View and check whether the margin settings have been really changed through program or not.


Note:If any value is less than the allowable range, based on the printer driver settings, the printer may fix it to the allowable range automatically. In that case you may find some value is greater than what you have specified.


You can do a sample run of the Program by typing SetMargins "YourReportName" in the Debug Window directly, without the use of Form or Command Button.


You can run this Program from within the earlier PaperAndOrient() Program to change the Margins also along with the Paper Size and Page Orientation. All the three set of values can be changed by calling the PaperAndOrient() Program alone.


The modified PaperAndOrient() Program is given below:

Public Sub PaperAndOrient(ByVal strName As String)
Const DM_PORTRAIT = 1
Const DM_LANDSCAPE = 2
Const DM_PAPERSIZE = 9
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report

' Opens report in Design view.
DoCmd.OpenReport strName, acDesign
Set rpt = Reports(strName)

If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.lngFields = DM.lngFields Or DM.intOrientation

' Initialize fields.
DM.intPaperSize = DM_PAPERSIZE
If DM.intOrientation = DM_PORTRAIT Then
DM.intOrientation = DM_LANDSCAPE
End If

' Update property.
LSet DevString = DM
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
SetMargins strName
DoCmd.Close acReport, strName, acSaveYes
DoCmd.OpenReport strName, acViewPreview
Set rpt = Nothing

End Sub




Public Sub SetMargins(ByVal strName As String)

Dim PrtMipString As str_PRTMIP
Dim PM As type_PRTMIP
Dim rprt As Report
Const TWIPS As Long = 1440

Set rprt = Reports(strName)
PrtMipString.strRGB = rprt.PrtMip
LSet PM = PrtMipString

' Set margins.
PM.xLeftMargin = 0.75 * TWIPS
PM.yTopMargin = 0.5 * TWIPS
PM.xRightMargin = 0.5 * TWIPS
PM.yBotMargin = 0.5 * TWIPS

' Update property.
LSet PrtMipString = PM
rprt.PrtMip = PrtMipString.strRGB

Set rprt = Nothing

End Sub




The Dimensions of the Reports, Forms and other Objects are measured internally in Twips rather than in Inches or Millimeters. We are allowed to change the measurements on the Property Sheets of Report, Form or other Objects in standard measurements manually, like Inches or Centimeters or in any other regional values. They are automatically converted into Twips internally. But, in programs we have to do that work before changing the values of the Property of objects.



1 Inch = 1440 Twips
1 Inch = 72 Points
1 Point = 20 Twips
OR
1 Twip = 1/20 Point



We have used Constant values in the Program for Page Size, Orientation and Margins for simplicity. You can modify the Code to pass these values as parameters along with the Report Name, when the Program is called for each Report. This will give more flexibility and the Program can be called for Reports with different Page Settings.


Next we will see how to change the values on the Columns Tab of the Page Setup Dialog Box of File Menu.



StumbleUpon Toolbar



Control Tip Text and Time Delay
External Files List in Hyperlinks
Combo Box Column Values
Drill-Down Inquiry Screen-2
Drill-Down Inquiry Screen

Labels:

0 Comments:

Post a Comment

Note:Comments subject to Review by Blog Author before displaying.

Links to this post:

Create a Link

<< Home


Creative Commons License
Learn MS-Access Tips and Tricks by msaccesstips.com is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 India License.



This Page is best viewed with 1280 x 1024 Resolution

   FEATURED LINKS
SITEMAP
Command Button Animation
3D Headings on Forms
MsgBox & Office Assistant
Reminder Ticker
MS-Access & E-Mails
Automated E-Mail Alerts
MsgBox with Options Menu
Colorful Command Buttons
Configure Lotus Notes
Alerts through Network
Running this site has become a costly affair as the revenue from Ads is not sufficient to support it. If you find these pages informative & useful and would like to extend a helping hand, then please do it here.





Link Back to us with this Button

Learn MS-Access

Copy and Paste this HTML Code in your Webpage


Add to Technorati Favorites

Programming Blogs - Blog Catalog Blog Directory
Powered by FeedBurner
Add to Google

Software
Computers blogs
TopOfBlogs




AddMe - Search Engine Optimization Submit Your Site Free!
Go BlogZ Ave Blogs
eBlogzilla Changing LINKS
LS Blogs Blogarama
blog search directory BlogUniverse
Find Blogs in Directory RSS Directory
blogskinny.com ShowcaseBlogs.com
Amfibi

Search Engine Optimization and SEO Tools
Dmegs Web Directory Takeaway for Sale Businesses For Sale
Free Submission Directory Free site submission

Free Listing
 





Free Page Rank Checker

AddThis Social Bookmark Button

Enter your email address:

Delivered by FeedBurner



Top Blogs


Microsoft Access is the Jewell among MS-Office suite of Applications. Its Security features are excellent and works fine in Network environment. MS-Access can link/upload data from any Data Source. Applications that you design should be user-friendly and visually pleasing too. Here I would like to share my experience in Microsoft Access Programming with you and I am sure that you will find them interesting too.

My Photo
Name: Ramachandran Pillai
Location: Cochin, India

I am not an Access Guru and not through MS-Access yet. More to learn and I don’t think that aspect has any end because others have their own style of using this tool. We can learn lot more tricks, other than what we already know, from others too. My programming skills in COBOL, BASIC, Turbo-C, dBase, FoxPro, Visual Basic & Basic HTML attained through self-learning. I wrote my first COBOL Program in 1975 for ICL1901, 3rd Generation Main Frame Computer. Worked as a Computer Operator (NCR VRX8555 Mainframe Machine upto 1990) with M/s. Y.B.A. Kanoo, Saudi Arabia. Started using MS-Access Ver.2 in 1996, when dBase III+ and Foxbase (later version Foxpro) were my favorite DBMS. During Last 13 Year period I have developed more than 45 In-House Applications (medium & small) under MS-Access for our Organization, a leading Automotive Company in Oman. All the Applications are fully Secured and runs under Windows Network. It is my pleasure to share my experience with others. Anything interesting that you would like to share with me, please do. My E-mail Address: aprpillai@msaccesstips.com


If you need a Demo of any of the Topic explained here, send me an E-mail to: aprpillai@msaccesstips.com
with the Topic Description, I shall try to send a sample database to you.


Access Tips | Email | Reports | Report Tricks | Graphs | Forms | Menus | Animation | Security | Internet | How TOs | Linking | Query | Progress Meter | Alerts | Process Tips | Access Functions |




Site Designed by:www.msaccesstips.com