change .ribbonname property on open - ms-access

Context:
I have an Access database application that was built in Access 2k. I have a custom ribbon built that I am playing around with, and I also have some user "security" in this app.
When a report opens, I want to check the username and switch to a different ribbon for specific users. I would think that this code would work:
The Code:
If GetUserName() = "admin" Then
Me.Report.RibbonName = "CustomPrintPreview"
Else
Me.Report.RibbonName = "MSToolbar1"
End If
The Problem:
This code seems to execute (and it's not doing On Error Resume Next). However when the open event ends, the report opens with no data (when there should be data). If I remove this if block, it runs fine aside from setting the correct ribbon. I should mention that if I manually set the RibbonName property for the report, both ribbons work fine, so it is not a problem with the ribbons themselves.
I'm currently using access 2007, but this will be deployed for 2010 versions as well. Does anyone know what's going on here?

Related

VBA behaves differently after close and re-open

I am using Access 2007 on a PC running Windows Vista.
The Access database with VBA code in many modules works as expected. However, one module acts differently after I have exited the database and re-entered. As soon as I re-enter, I can select View Code and Save without changing any code and the program goes back to working the way I expected. Any ideas?
Details:
The Access module with the inconsistency opens Word 2007 and creates a new document from a template (.dotx) file using bookmarks to merge Access data into the document. This works as designed without a problem and works every time. Once the document is created, the vba code calls the Word window to front. This does not happen unless I select View Code and Save. I do not have to modify any code, just select Save. Then it works as expected until I close the database. When I next open the database and select the button that creates the Word document, the document is not brought to front but remains behind the Access window. If I select View Code and Save, the subsequent documents created during that session come to front as desired. This is consistent and repeatable.
I am not sure about why this is occurring, but a quick fix that I thought might work would be to programmatically save the module when you load your DB.
docmd.save acmodule, "module name"
Hope this works!

Access Application.Quit not working, SharePoint Web Database

In my database (Access 2013, .accdw), I am checking the user's current version in the Form_Open event. If it is not up to date it triggers an external command to download a fresh copy and then is supposed to close itself to allow for the update. The problem is that after Application.Quit is triggered, access closes but instantly reopens, blocking the download. I've stripped out all the code I can to isolate the problem.
If 1 = 1 Then
Application.Quit
End If
Simplified pretty far, right? It should always just close as soon as the form is opened. With this as the only code in my Form_Open event which is the only code in the form, it still closes, reopens, and then closes again. Docmd.Quit has the same effect. I've tried too many variations to enumerate. In a button this code works fine, but I need it to run the check before it loads any data (the linked tables may be being altered while we change versions).
Any ideas how to make it stay closed the first time it closes?
I think it reopens because your external code (.bat file ?) reopens it. It's not an Access problem. Have you checked the numerous tools you can find for Access automated client deployment ? Here are the first 2 I found:
http://www.databasejournal.com/features/msaccess/article.php/3286111/Automatically-Deploy-a-New-Access-Client.htm
http://www.devhut.net/2015/06/30/ms-access-deploying-your-database-front-end-to-your-users/
Your code works for me in a Form_Open(), but then this is Access 2010 and no Sharepoint.
You may have better luck by Creating an AutoExec macro that calls an initialization function that does the version check, instead of having a form open automatically.
If the version check is ok, then open your start form from the function.
The easy work-around is to always fetch the current version and then launch it.
This way there's no fuzz and the user always run the latest version.

MS Access 2010 Ribbon Not Changing From Report To Form

In an application I have two ribbons: a "General" one which is used for all forms, and a reports-specific one for all reports. From a "Reports Manager" style form, a user can select a report and preview it.
When the report opens, it correctly displays the Reports Ribbon. However, when the report is closed, the Reports Manager form is still showing the Reports Ribbon, instead of the general one.
Once this form is closed, the Ribbon changes back to the general one.
Note that users access this application, as an accde, via Terminal Server.
This incorrect behaviour does NOT happen on a local development machine, so I suspect it is due to a TS 'refresh' issue - which I have noticed in a couple of other circumstances.
Is there anyway to 'force' a refresh of the Ribbon when a report is closed, and the Reports Manager form is therefore displayed?
I would consider in your startup code grabbing a handle to the main ribbon (that is not re-displaying). Then in the reports on-close event execute a ribbon invalidate command like this:
MyMainRibbon.Invalidate
So you can “force” a ribbon re-plot. This does suggest you always use a accDE, since with a accDB then any un-handed error will ALSO lose the above global var that holds a reference to the ribbon.

Modal Popup causes access to crash

I am working on a modal popup form in access and I have the following problem:
When I incidentally open my form in "form view" instead of "design view" It causes a VB script error (which is normal, because it tries to get information from another form which is not open).
So VB tells me there's an error, I tell the VB debugger to stop the execution of the code, and thus the form does not open, but then access is not re-enabled.
I can't regain any form of control, and it's not an endless loop or something like that, because Access is still running correctly according to my task manager.
So far the only solution I found was to close access through the task manager, but it doesn't seem normal to me.
Here are a few suggestions:
http://www.pcreview.co.uk/forums/control-location-screen-form-opens-t4041436.html
You can also try to modify a bit of your form, move it to a new/good position, and saving it. I have had this happen to me in the past.

MS Access Treeview error loading ActiveX control [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
MS-access doesn't catch treeview events after win sec-update
recently an error appeared with a Treeview element in my access form.
The expression Expand you entered as the event property setting produced the following error: There was an error laoding an ActiveX control on one of your forms or reports.
When I click "OK" (only opportunity) the next error appears (Expand is replaced by MouseMove, MouseDown/Up, DblClick etc.), when I press Keys the KeyDown/Up/Press Message appears etc.
When I interact with the TreeView then the "Expand" is replaced by e.g. NodeClick or Collapse.
Every message only appears once, when I performed every possible Event no message pops up - but the treeview doesnt work, it doesnt open any form (the treeview is used as a menu).
The mysterious thing to me is - last week those Access Databases all worked fine - we have a database for every customer (frontend and data together) and now suddenly every database 'crashes'. I assumed that the ActiveX Treeview Control was changed by a Windows Update or something similar but also an old WinXP laptop throws the same error messages.
Even a database that hasnt been opened for 2 weeks and definitely worked back then doesnt work anymore. So from my point of view there cant be anything in the code that is wrong.
Nevertheless I tried to set a breakpoint in the Form_Load event, but the Expand Error already pops up before the first line of OnLoad is executed.
The OnLoad Event is the only event that is specified (GUI says "Event Procedure", its VBA Code only) and all other fields are blank (and no code specified).
I created a blank VBA for e.g. MouseMove, but the error still appears.
What is this error and where does it come from? Hope anyone can help.
Regards,
Matthias
P.S.:
My Treeview Project
Via this Link you find the files for a treeview project in MS Access (mentioned in the first answer). When I download these files the same kinds of error appear.. so it definitly has to do with the activeX controls, right? Is there anybody where these files work, and if so - why? Hope anybody can help..
I was having the same problem - treeview worked last week not today in either 2007 or 2010 Access, multiple PCs. Problem was Windows update. (See link http://support.microsoft.com/kb/2687441). I created and ran the batch file as indicated in the kb article and my Treeview now works.
I got the same error. I found the solution in the following link:
http://mymsaccessblog.blogspot.nl/2008/09/my-teeview-project-episode-5-using.html
I added the following sub listed below and adjusted it with the key I used and it worked.
I hope this helps you as well. Sorry if the formatting is not good. First time I post anything
Private Sub xProductTreeview_Click()
Dim nodSelected As MSComctlLib.Node ' a variable for the currently selected node
Set nodSelected = Me.xProductTreeview.SelectedItem ' get the currently selected node
If nodSelected.Key Like "Prod=*" Then ' are we on a product node
ElseIf nodSelected.Key Like "Cat=*" Then ' are we on a category node
Else ' somehow this is neither a category or product node
End If
End Sub