How can I hide buttons on an empty subreport in MS Access? - ms-access

Note: I've been debating on whether this should go into SuperUser or StackOverflow... I figure that SU is better, but please let me know is SO is a better fit for this question.
Alright so I'm kind of pulling my hair out over this. I have a database where I'm tracking questions, issues, change requests and more in regards to a piece of software. An important aspect here is to be able to add attachments (bug reports, screenshots, etc.). I read that generally it's better to create your own attachment handling system in Access because using the native attachment field can negatively impact performance, so I did just that. Plus, I prefer my implentation much more than the native implementation for the most part, so that's a bonus.
I created a report with different buttons to add, copy, and delete files with different buttons including the VBA code to handle everything. I then add the report as a subreport to the report or form in question. Example: Someone wants to ask a question and wants to attach a screenshot and an error log. The main form handles things like question and tags, and the subreport handles the attachments. To the right of every record (attachment) I have two buttons - one to open a dialog to copy the file somewhere locally, and the other to delete the attachment. Everything works fine, with one annoyance that should be minor but is really getting on my nerves: when the subreport is empty, it shows the two buttons in the otherwise empty details area. This is pretty confusing to me because I only have this empty line when the report isn't showing any records. As soon as I add an attachment, the new attachment/record uses that line (it's not as if the empty line is Access presenting a row for entering a new record).
In pictures (in German as I'm doing all of this in German):
When the attachments report has records, it looks like this:
Translations: Anhänge => Attachments; Dateiart => File type; Dateiname => File name; Datum => Date; Größe => Size; Kopieren nach... => Copy to...; Löschen => Delete; Anhang hinzufügen... => Add attachment
I've also blacked out some info for privacy reasons, but I hope everyone gets the idea.
When the subreport has no records, it looks like this:
I've scoured the web for solutions and I have yet to find anything that worked. I've tried setting the buttons to invisible in the "NoData" event, only to figure out that that event doesn't seem to fire when the form is a subform. I've tried adding code to the "Format" event of the details area, but that doesn't seem to fire either. Does anyone have any idea how I can solve this majorly annoying minor annoyance? Ideally I'd also remove the header lines and change the title as well but getting rid of the buttons would be a great start.

It looks like an empty record, so try using the OnCurrent event of the subform:
Me!DeleteButton.Visible = Not Me.NewRecord

Related

Can we write a function in SSRS globally

Im currently using SSRS-2008R2. I've an scenario where i have to maintain the External image as a logo for each reports we have. Not, only that, we have our custom date formats that what we should change according to the Date Type users define in an asp.net application.
There are lot of things we have to do on every report. Thats my problem.
Following is the one of them Im currently sharing as example :
Currently i maintain the following function for each reports i've:
Public Function GetLogoImage() As String
Dim ImageLogoURL As String
if Globals!ReportServerUrl is nothing then
ImageLogoURL = "http://localhost/ReportServer" + "?%2fImages%2fLogo"
else
ImageLogoURL = Globals!ReportServerUrl + "?%2fImages%2fLogo"
Return ImageLogoURL
End Function
I hope, i asked question clearly. Im newbie in SO.
Thank you in advance.
If you have a list of functions that you wish to apply to multiple reports and you're not willing to copy them to every single one of them, you can create an external library and then add it as a reference to every report.
This is quite simple to do and there's lot of documentation around the web.You can start here. You will, however, have to maintain this external library but if you have a lot of code, I personally think this is a much better solution.
If you want to have a predefined layout, you may want to consider having a master report and then include other reports as sub-report objects, but you'll lose some flexibility design wise.
Since the accepted answer is more of a comment and the link provided is broken, i'll provide my answer for people who might need a quick guide on how to use custom code in ssrs:
In Design view, right-click the design surface outside the border of the report and click Report Properties.
Click Code.
In Custom code, type the code. Errors in the code produce warnings when the report runs.
Once you press ok, to call the function that you saved you just need to right click on a cell, select "Expression" and paste in the following string: Code.GetLogoImage
More detailed source here.

Why does my code produce a different result on occasion in apps-script?

I have a very strange problem. I load my app, switch to the correct tab and then press the button I need to press. This runs a function and when I first load the page it may only provide part of the correct result. However if I wait a few seconds it produces the correct result in full. Any ideas why this might be happening?
Additional Information
The button simply checks through a list of objects returned via ScriptDB. Objects that are valid are displayed and objects that are in-valid are not. If the object appears again in updates the text to display how many have been found in the list (eg: the label would change from "Object A" to "Object A (2)").
It seems to me like it doesn't have the rest of the list somehow as it doesn't always stop at the same object. It's Very strange and not something I've experienced before. The other features of my app using ScriptDB work completely regardless of how quickly I use them.
I've figured it out now. I somehow had some erroneous data in the database which was returning a null field. I can only assume that this was from a import that I did last week from a spreadsheet.
This was copied from my comment to show that it has been resolved.

Add A Background

I was wondering if there was any way of changing the background in access. The standard grey is ok but I would like to change it to an image that shows instructions or what was updated last. Also, if I can allow a user to change the background to an image of their choice that would be cool as well.
Can this be done
To be honest, I'm not sure if this is possible or not, but if it is, I'd advise you not to do it. Why?
Users will expect instructions under a help menu or on an intro
splash form
They will expect info. like what was updated last to appear in more
conventional places like the status bar
Allowing users to personalise your application with their photos can
make your application look pretty bad and increase load times.
Only advice though - good luck with it!
I have been able to allow users to change the background of the database. It works great and it works no matter what computer they log onto the database from. I did have a problem with remote users so I added a macro that allows them to disable the functionality. It works great. It was a little complicated to se up initially. Some of the modules below may have more stuff contained in them then what is needed for the purpose of this question. But here is what I did to make it work:
Add the Following modules to your database: modChangeMDI, SetBackgroundImage, and clsCommonDialog
Link to a zip file containing the code for the above modules: http://www.filedropper.com/changebackgroundimage
You can set the default location that a users sees when the search for file dialog pops up. This is located in the ThisFileToOpen function of the SetBackgroundImage module.
clsCommonDialog <-- Used to open the find file dialog box
modChangeMDI <--Used to change the background image
Create a table called $BackgroundLocation with the following fields. On my database this is contained in the backend database.
ID (AutoNumber, Primary Key)
UserID (Text, Required, 250 in length, don't allow zero lengths)
BackgroundLocation (Text, 255 in length, not required)
DisableBackground (boolean)
Create an AutoExec macro and add an action that runs the code SetTheBackgroundPictureOnStartup (1)
Create a BackgroundDisableEnable macro and add an action that runs the code DisableEnableBackground()
Create a BackgroundSet macro and add an action that runs the code SetTheBackgroundPictureOnStartup(2)
Then assign the BackgroundDisableEnable and the BackgroundSet macro to their own menu item.
When the database opens it will run the AutoExec by default.
You can use a start-up form as I suggested above. You can even base the start-up form on a comments table that can be edited by the users and will display the most recent and / or relevant information. The form can be displayed at start-up and then referred to at any time by the users.
In the past, I have included a ? button on forms that open such a form at the relevant page.

MS Access: Reports referencing other reports

I have several MS Access 2010 Reports that contain controls that reference other controls on other Reports. So, for example, if report1 has a text box called report1_textBox, and this text box gets its value from a text box on report0 called report0_textBox, then I set the Control Source property of report1_textBox to:
= [Reports]![report0]![report0_textBox]
I created a Form that the user can use to select Reports to open, and when the user selects a Report that depends on other Reports, my code opens those Reports before opening the selected Report. This works fine in some instances, but in other instances I get some strange behavior.
Going back to the example above, I encounter situations where even if I open report0, then open report1, the text box report1_textBox displays #Error as if report0 is closed or does not exist. But if I then just click on report0 and change its view then change it back, then go back to report1 and scroll a little, the text box report1_textBox "magically" changes from #Error to the proper value. I tried hitting the "Refresh All" button after opening the reports, and it does not update the text box.
Does anyone know of a way to fix this or at least work around it?
Thank you!
(Adding: Ideally, I do not want to open multiple reports like I'm doing now. If the user wants to view a report, I would like to only open that report, but from what I understand, if the selected report needs data from another report, that other report needs to be open. I can ultimately solve this by writing VBA code to execute queries, but I would like to avoid this, especially since I already have the data I need - it's just on another report. Does anyone know if it is possible to realize this ideal situation? Thanks!)
I would suggest going with VBA code for this.
Your question, actually, contains an answer (partial) - if you need data from another report that report must be opened first. However, the following code might help you somewhat.
You can open report(s) as hidden:
...
DoCmd.OpenReport "report0", acViewReport, , , acHidden
...
But again, I would recommend to write VBA code to pull the data using either existing queries from other reports or create new ones [queries].

First page of MS Access Report does not seem to call On Page Event

I have coded a MS Access 2000 report that displays a calendar with one month per page and projects added to particular days. The only data in the underlying record source is a list of months. The structure is created via the On Page event, which also reads in other data.
When this report is opened, I've noticed that the On Page event does not seem to be triggered for the first page. (I attribute this to the fact that On Page in reports is activated when a page is cached rather than when a page is displayed, such as On Current for Access forms.)
When the report is displayed my work around is to use the On Activate event to force the On Page subroutine to run even though that event has not been called. However when the report is exported it does not trigger the On Activate event and the first page of the export is in one of two formats:
1) if the report was open in Access (ie On Activate had been triggered previously) the first page is identical to either the page after the one being displayed or the last page, except with the correct month (which comes from the underlying record source)
2) if the report was not open in Access the first page contains just the structure within the report design view (ie lots of empty boxes)
My best workaround is to force a (otherwise pointless) cover page to ensure the first page contains nothing that needs code to run, but this is far from ideal. Can I force the code to run for the first page of an export? Or maybe I'm misunderstanding how On Page works and I need to restructure my code? (I've also noticed that On Page seems to run twice for the last page).
I would recommend restructuring your code so that you build your data in one query, multiple queries, or in VBA, and then open the report with the new datasource. I might still have Access 2000 at home to check, but at work I can test both 2003 and 2007, and in both versions, the OnPage event fired before each page was displayed. If you are experiencing different behavior, I suspect it's because Access isn't sure how to handle what you are asking it to do.
Typically a report like the one you are describing would be designed the other way around: the datasource for the report would contain all the project information. Is there something about the data you're trying to display that prevents you from building a query that would contain all of it?
Have you considered the Format event for the various sections, especially the Detail section? Format or Print are a more usual events for manipulating reports.