Question : Change print margins in vba

Hi experts,

I would like to change the print margins for a page using VBA - is this possible?  I could change these settings per report, but for some reason, even though I have manually changed these settings, when I close the db down and restart, the report margins go back to a default of 24.

I would like the margins to be:

Top: 15.01
Bottom: 15.01
Left: 24.01
Right: 15.01

Can anybody help?

Thank you.

Terry

Answer : Change print margins in vba

Ah, what?  You mean those to be millimetres, right?  A 15 centimetre margin is a wee bit wide, don't you think?

You can either place the following code in each report's Open event:

  Private Sub Report_Open(Cancel As Integer)
     Const mm = 56.7  'number of twips per millimetre.
     Me.Printer.LeftMargin = 24.01 * mm
     Me.Printer.TopMargin = 15.01 * mm
     Me.Printer.RightMargin = 15.01 * mm
     Me.Printer.BottomMargin = 15.01 * mm
  End Sub

Alternatively you could try setting the default margin options in access so that when a report is inexplicably reset to the default, at least they should be the correct default.

In database view, select Options... from the Tools menu, then go to the General tab.  Print margins should be in the top left quarter of the dialog.

PS: When you say that you change the margins and they return to the default after you close and reopen the report, are you changing them in design view, or just in print preview mode?  Because print mode changes made in print preview aren't meant to be persistant.
Random Solutions  
 
programming4us programming4us