I've got a MS Access form that contains a subreport.
This is to allow a sort of dynamic preview of what you are going to get when you launch the print (in fact it's a form that allows to chose among different print layouts).
Let's say that my report is this:
It has also non-fixed fields, but it's not relevant for this issue.
The report is quite small and when presented in the form I would like to apply some sort of zoom, which actually I can't find.
Even if the subform/subreport control is much larger than the report, there seems not to exist a property that allows you to resize the report.
The result is this:
I tried setting Default View to Print Preview, no changes in visualization.
I hoped that switching to Print Preview would allow a greater control of the zoom (like actually happens when you launch a 'standard' print preview).
I tried setting FitToPage to true.
I tried to set AllowReportView to force the Print Preview, with no luck. At this point i think Print Preview is simply not allowed in a report inside a form.
Is there some (or some other) way to address this smallness problem?
Thanks in advance
P.S. If zooming is not possible, I would at least highlight the real report area because showing only the borders of the subform/subreport control would be confusing in this case.
Correct, report on form can only be displayed in ReportView. I don't think you can get 'zoom' feature by any method. As for 'highlight' of report area, code could set Backcolor property of each report section when report loads, like:
Private Sub Report_Load()
With Me
If .CurrentView = 6 Then
.ReportHeader.BackColor = vbYellow
.ReportFooter.BackColor = vbYellow
.PageHeaderSection.BackColor = vbYellow
.PageFooterSection.BackColor = vbYellow
.GroupHeader0.BackColor = vbYellow
.GroupFooter1.BackColor = vbYellow
.Detail.BackColor = vbYellow
End If
End With
End Sub
Might want to set all controls with transparent BackStyle.
Or instead of setting Backcolor, use a background image (watermark) on report.
Related
I have the following (simplified) VBA code that demonstrates the problem while resizing a report and its controls from a module. To reproduce, create a new blank database, add a table and a report, then add this code into a new module:
Public Sub ResizeReport()
Dim rr as Report
Dim cc as Control
Set rr = Screen.ActiveReport
For Each cc in rr.Controls
cc.Width = 1 * 1440
Next
rr.Width = 5 * 1440
End Sub
If I open a report in Design View and run the macro, the changes stay when I change to other views (such as Report View, Layout View, or Print Preview). However, if I open the report in Layout View and run the macro, the report and its controls are resized, but as soon as I change the view mode, the report reverts to its state before the resize.
Please note that this issue does not occur if I manually resize the report/controls using drag handles or the Property Sheet while in Layout View.
Is there a command I need to issue after resizing the report/controls from VBA while in Layout View to get the changes to stick? Or should I be resizing the report/controls using different VBA commands?
I am using MS Access 2010.
Thank you for the short yet detailed question and functioning "MCVExample". I may need to refer other newbies to this question as an example of a perfect question. +1 for that even though the answer seems obvious. :)
You should save the report before changing it's view.
DoCmd.Save acReport, rr.Name
This will force the changes to "stick". The logic behind the report reverting to its previous state when changing view is to allow for dynamic, temporary changes at runtime, without permanently affecting the report.
More Information:
MSDN : DoCmd.Save Method (Access)
MSDN : Set Form, Report, and Control Properties in Code
I am trying to implement a 'Flag' w/ a menustrip.
I have an image list w/ a red flag and a black flag.
When I click the menu item, i want to toggle the image.
The problem I have is that once I change the image, it wants to do SizeToFit which makes the Icon roughly the height of text. I dont want that. I want the Image to be its actual size.
I have tried putting the statements in different orders, nothing i have tried seems to work.
Currently, I have the button set to the black flag at design time.
This code shows me trying to change to a Red flag.
tsbFlagPatient.Image = ilFlags.Images(1)
tsbFlagPatient.ImageScaling = ToolStripItemImageScaling.None
tsbFlagPatient.DisplayStyle = ToolStripItemDisplayStyle.Image
[If there is some better way to approach toggling the image, im open to that. That seems like a separate question. ]
I was unable to make ImageScrolling work.
Since I dont need text here, I used BackGround Image and set
BackgroundImageLayout = Stretch
This allows the images to be the right size.
You can turn AutoSize = false and then manually set Height, Width to fine tune your menu's size.
I did reconsider the ImageList and changed the images to being stored in the project Resources. This is the code to toggle the image
Public Sub SetFlagImage(flagSet As Boolean)
If flagSet = False Then
btnFlag.BackgroundImage = My.Resources.appbar_flag_wavy_black
btnFlag.BackgroundImage.Tag = "black"
Else
btnFlag.BackgroundImage = My.Resources.appbar_flag_wavy_red
btnFlag.BackgroundImage.Tag = "red"
End If
End Sub
This had no effect on the question posed here. In general, probably better than having an image list because all forms can access it.
I have a form that acts as a subform in one case and as a dialog box in another. To do this I have used a boolean. When its true I want the form to open as a dialog. For this I have used the following statement inside the if condition:
Me.Borderstyle=3
But on running the application it gives error 2136 that says:
open the form or report in design view
Debugging leads me to the line with the borderstyle code.
What could be the reason? Is it not possible to set borderstyle through code?
The form works fine if i comment this part... it's just that it's not visually appealing if it doesn't look like a dialog.The code is as below:
Private Sub Form_Load()
If chk = True Then
WindowS Me, 2, 2, 90, 70
Me.first.Locked = True
Me.second.Locked = True
Me.BorderStyle = 3
Else
WindowS Me ' resize window and controls to current screen resolution
Me.cmdCLOSE.Visible = False
End If
End Sub
Apppreciate the help.
The error message is pretty clear - you can't set this property in Form view, only in Design view.
For some reason this information got lost in the help file for Form.Borderstyle - it was present in older versions, as quoted here:
From the Access 97 VBA helpfile on the BorderStyle property:
"You can set the BorderStyle property for a form only in form Design view by using the form's property sheet, a macro, or Visual Basic."
It's the same for e.g. the Form.CloseButton property, here the help file mentions it.
IMO it makes sense that you can't change structural form properties like these when the form is open.
As to your requirement:
I have a form that acts as a subform in one case and as a dialog box in another.
Subforms don't have a border anyway, so why not simply set the border style to "Dialog" and leave it at that?
I have a situation in which text in one of the cells is massive.When I change the contents of this cell the previous value becomes a comment to that cell.Now the problem is, this text is so big that I cannot see complete text.If I use .Shape.Textframe.Autosize=true then I have to go on browsing till god knows when to see the text.
What I need to do is whatever and however big the text might be in Commnet.text,I want to show it in one and one place only.i.e when I hover on comment.
Place a TextBox where you will on your worksheet adjusted to the size you want, this still reads the comment although this is not on a hover, but perhaps will help
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not ActiveCell.Comment Is Nothing Then
ActiveSheet.Shapes("Text Box 1").TextFrame.Characters.Text = ActiveCell.Comment.Text
Else: ActiveSheet.Shapes("Text Box 1").TextFrame.Characters.Text = ""
End If
End Sub
Actually after considering this further you really are trying to get comment to act as you want. So I recommend Resize all comments in the selected area and on the same link further down the page Show Excel Comments in Centre of Active Window.
These get you closer to what i think you want.
How about a pop-up text box? I.e., the user clicks on the cell and a pop-up form with the text appears. The best part is you can make the pop-up as big as you want.
Personally, I would make the pop-up resizable, but with only the Close button at top. I can't think of a way to trigger this form with just a mouse rollover, but I'm only using 2003. Later versions allow you more tricks.
xlSheet.Range(xlSheet.Cells(rowCount,1), xlSheet.Cells(rowCount,8)).Merge
xlSheet.Range(xlSheet.Cells(rowCount,1), xlSheet.Cells(rowCount,8)).HorizontalAlignment = 1
xlSheet.Range(xlSheet.Cells(rowCount,1), xlSheet.Cells(rowCount,8)).WrapText = True
xlSheet.Range(xlSheet.Cells(rowCount,1), xlSheet.Cells(rowCount,8)).RowHeight=45
In onw of our application, we have some reports that need very specific margins that are dependant of the printer the user have. It is used to print into preformatted paper with blanks to fill and depending of the printer, the printing is off by some margins. To make things worse, we don't actually control what printer is used because it is not an internal application.
The only solution I could think of is to let the user configure the margins somehow. I thought I could just dynamically change the report margins like I did with datasources and actual report (I have one control that is used to display every reports from my application and it works alright), but I can't seem to find that damn property to do so. There is a margin property on the report viewer but it's for the form display so it doesn't cut it.
Does anyone knows how to. What I was thinking to do is to define the margins before the user loads the report, i.e. when he clicks on the report button, I load the report, set the margins (or vice-versa is necessary) and then display it.
Before someone mention it, I know the user can, once the report is loaded, change the page setup to fit his needs, but this has two drawbacks. First one is that it is not saved each time and I need it to be 'saveable' and by users. The second one is that Report viewer seems to have some bugs when the regional setting aren't set to what it's expecting and we can't force the users to changes their setting to accommodate one application.
Edit: Forgot to mention, it this is of any uses. My reports are all local reports.
'creates a new page setting
Dim instance As New PageSettings()
'create the new margin values (left,right,top,bottom)
Dim value As New Margins(0, 0, 0, 0)
'gives your new pagesetting a value
instance.Margins = value
'report viewer now sets your margins
ReportViewer1.SetPageSettings(instance)
You can't do this directly. Try controlling your margins in the report with report parameters.
Well, I just had this similar problem; needed a report to have 0" margins, otherwise the blasted thing went from 2 pages to 6, and it split the data vertically, so the pages made no sense. I was having to set it manually in the Print Setup to print, but the end goal of this report is to be emailed to customers as a PDF, and guess what, when I set the margins manually and exported, it still split into 6 pages and bombed out. So risking everything, I tried one last supreme effort to fix this blasted thing - I opened up the .rdlc with word pad, and miracle of miracles, found 1in, etc. I set all those buggers to 0in, saved, ran my .net code (2008), opened up Print Setup, and hallelujah, there was my 0in settings. Now for the supreme test - I exported it as a PDF, went to the file, and son of a gun! Sweet. There were two crisp clean perfectly laid out pages. All was beneficent in the universe, I calmed down and let the midiclorians flow through me, and just basked in a moment so rare that it is rarely realized by some - a simple fix.
Check out the ReportPageSettings class, part of the report viewer control. Setting those values looks like it should get you what you need.
More settings;
Dim myPageSettings As New PageSettings()
myPageSettings.Margins = New Margins(0, 0, 0 , 0)
Dim paperSize As PaperSize = New PaperSize()
'ToDo: update with the PaperKind
'that your printer uses
paperSize.RawKind = PaperKind.A4
' paperSize.RawKind = System.Drawing.Printing.PaperKind.A4
myPageSettings.PaperSize = paperSize
'False for "Portrait"
'True for "Landscape"
myPageSettings.Landscape = False
'report viewer now sets your margins
ReportViewer1.SetPageSettings(myPageSettings)
this code work with me, the numbers in mm
Dim newPageSettings As New System.Drawing.Printing.PageSettings
newPageSettings.Margins = New System.Drawing.Printing.Margins(50, 100, 45, 45)
ReportViewer1.SetPageSettings(newPageSettings)
im using vb.net 2013