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

Problem when I try and modify report layout with code... 1

Status
Not open for further replies.

perfessor

Programmer
May 12, 2000
5
US
Hi,<br>I have an Access 2000 application, and when I send out the runtime version, the margins and orientation for my reports gets reset.&nbsp;&nbsp;I researched it on the net, and modified a function from someone elses modification of code in Microst Access 95 Developers Handbook.&nbsp;&nbsp;<br>It works great to change the orientation from Portrait to Landscape, but when I use it to change the margins, it does not work.&nbsp;&nbsp;When I go to a report, it says printer not found, and resets the margins to one inch.<br>Any insight into my problem?<br>Thanks,<br>Rik<br><br>Code:Option Compare Database<br><br>Const glrcDeviceNameLen = 32<br>Const glrcFormNameLen = 32<br>&nbsp;<br>' This is the number of bytes in the fixed portion of<br>' the DEVMODE structure. We've just broken the<br>' two sizes apart in case the fixed portion of<br>' the structure changes.<br>Const glrcDevModeSize = 148<br>' This is an arbitrary value. Based on experience,<br>' it ought to be large enough.<br>Const glrcExtraSize = 1024<br>Const glrcDevModeMaxSize = glrcDevModeSize + glrcExtraSize<br>&nbsp;<br>' Structure for prtDevMode<br>Type glr_tagDevMode<br>&nbsp;&nbsp;&nbsp;&nbsp;strDeviceName(1 To glrcDeviceNameLen) As Byte<br>&nbsp;&nbsp;&nbsp;&nbsp;intSpecVersion As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intDriverVersion As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intSize As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intDriverExtra As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;lngFields As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;intOrientation As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intPaperSize As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intPaperLength As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intPaperWidth As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intScale As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intCopies As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intDefaultSource As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intPrintQuality As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intColor As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intDuplex As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intYResolution As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intTTOption As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intCollate As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;strFormName(1 To glrcFormNameLen) As Byte<br>&nbsp;&nbsp;&nbsp;&nbsp;intLogPixels As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;lngBitsPerPixel As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngPelsWidth As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngPelsHeight As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngDisplayFlags As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngDisplayFrequency As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngICMMethod As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngICMIntent As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngMediaType As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngDitherType As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngICCManufacturer As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngICCModel As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;bytDriverExtra(1 To glrcExtraSize) As Byte<br>End Type<br>&nbsp;<br>' Structure for prtDevNames<br>Type glr_tagDevNames<br>&nbsp;&nbsp;&nbsp;&nbsp;intDriverPos As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intDevicePos As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intOutputPos As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;intDefault As Integer<br>End Type<br>&nbsp;<br>' Structure for prtMip<br>Type glr_tagMarginInfo<br>&nbsp;&nbsp;&nbsp;&nbsp;lngLeft As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngTop As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngRight As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngBottom As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngDataOnly As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngWidth As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngHeight As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngDefaultSize As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngItemsAcross As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngColumnSpacing As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngRowSpacing As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngItemLayout As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngFastPrinting As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lngDataSheet As Long<br>End Type<br>&nbsp;<br>' Temp structure for prtDevMode info.<br>Type glr_tagDevModeStr<br>strDevMode As String * glrcDevModeMaxSize<br>End Type<br>&nbsp;<br>Public Function SetReportFormat(strRptName As String) As Byte<br>On Error GoTo Err_SetReportFormat<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim DM As glr_tagDevMode<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim PS As glr_tagMarginInfo<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim DMStr As glr_tagDevModeStr<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim PSStr As glr_tagDevModeStr<br>&nbsp;&nbsp;&nbsp;&nbsp;'Open report in design view<br>&nbsp;&nbsp;&nbsp;&nbsp;Application.Echo False<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.OpenReport strRptName, acViewDesign<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Get the DevMode settings<br>&nbsp;&nbsp;&nbsp;&nbsp;DMStr.strDevMode = Reports(strRptName).PrtDevMode<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Put the DevMode settings in User-Defined Type structure<br>&nbsp;&nbsp;&nbsp;&nbsp;LSet DM = DMStr<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Change the Paper Orientation to Landscape<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;DM.intOrientation = 2<br>&nbsp;&nbsp;&nbsp;&nbsp;'Assign changed setting back to User-Defined Type string<br>&nbsp;&nbsp;&nbsp;&nbsp;LSet DMStr = DM<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Assign changed setting string to the reports DevMode<br>&nbsp;&nbsp;&nbsp;&nbsp;Reports(strRptName).PrtDevMode = DMStr.strDevMode<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Save acReport, strRptName<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'Get the DevMode settings<br>&nbsp;&nbsp;&nbsp;&nbsp;PSStr.strDevMode = Reports(strRptName).PrtDevMode<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Put the DevMode settings in User-Defined Type structure<br>&nbsp;&nbsp;&nbsp;&nbsp;LSet PS = PSStr<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Change the Margins to minimum (I used msgbox ps.lngTop, etc., on a correctly formatted report to get these values)<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;PS.lngBottom = 1919251297<br>&nbsp;&nbsp;&nbsp;&nbsp;PS.lngTop = 1919251297<br>&nbsp;&nbsp;&nbsp;&nbsp;PS.lngLeft = 1277186120<br>&nbsp;&nbsp;&nbsp;&nbsp;PS.lngRight = 1277186120<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'Assign changed setting back to User-Defined Type string<br>&nbsp;&nbsp;&nbsp;&nbsp;LSet PSStr = PS<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Assign changed setting string to the reports DevMode<br>&nbsp;&nbsp;&nbsp;&nbsp;Reports(strRptName).PrtDevMode = PSStr.strDevMode<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Save the changes and close the report<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Save acReport, strRptName<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Close acReport, strRptName<br>&nbsp;&nbsp;&nbsp;&nbsp;SetReportFormat = True<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Application.Echo True<br>&nbsp;<br>Exit_SetReportFormat:<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Function<br>Err_SetReportFormat:<br>&nbsp;&nbsp;&nbsp;&nbsp;SetReportFormat = False<br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox Err.description<br>&nbsp;&nbsp;&nbsp;&nbsp;Resume Exit_SetReportFormat<br>End Function
 
Is this a network Printer?<br>I gusee you know in order to use a printer it has to be installed on each machine that wants to print to it.<br>Is the Printer on both Computers Spelled Exactly the same.<br>i.e. &quot;HP DeskJet 812C&quot; or something like that.<br>If it's a network Printer go in Network Neighborhood and find the printer in there. Then Right click on it and click Install. This will make sure every Computer that prints to that printer has the exact same spelling of it in the Printers Folder.<br><br><br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
I wish it were that easy.&nbsp;&nbsp;The application is on our salesguy's laptops, so there can be multiple printers.&nbsp;&nbsp;<br>I'm assuming my problem is that if you start setting printer options using the PrtDevMode method, it no longer assumes the default printer.&nbsp;&nbsp;Hmmm.. I wonder if I can get the settings for the default printer before starting this, and then slap them back in when I run this.<br>Rik<br>
 
Why are you writing a mile of code?<br>Access has powerful wizards to do 90% of what you are doing.<br>I only write Code when I need to do something un-usual.<br>Printing reports is as strait forward as it gets.<br>Laptop, Network or Not. Win 2000, NT 4.0, '98 or '95 I've never written any code to print a report.<br>We print reports simulataneouly all over the building from differnt platforms to 7 different printers.<br>Inkjet, Dotmatrix, and Laser<br><br>Perfessor step back a minute and take a hard look at what you are doing. Sounds like you are making a mountain out of a mole hill.<br>I have used Access and Visual Basic since their inception and have not written code to do a report for years now.<br>It's too much work for less results.<br><br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top