MS Access: Modal Dialogs with Transparent Backgrounds (redux)

Thursday, May 1, 2008

technology02.pngRob Cooper, of the Microsoft Access Team made an interesting post and a follow-up on how to add a transparent layer that cover the screen to focus the attention of the user to a login form or other important popup window.

The trick is to use some WIN 32 API calls to modify the transparency of a standard MS Access form made to cover the screen.

The effect is quite neat and I thought I would try it and make a sample database for others to tinker with it.
My version allows you to chose between covering the whole screen or just the main Access window and it will test if it’s running under a Remote Desktop Terminal and disable the layer in that case.

The transparent layer covering the main Window onlyThe transparent layer covering the full screen

Update 07MAY2008
Following Rob’s improvements I made another sample database that incorporates his code with a few improvements:

  • I added the LightBoxForm.LayerToFullScreen property so users can choose explicitly how they want the layer to be shown.
  • I moved the code to hide the layer into a Hide() sub so you can just show/hide the layer using LightboxForm.Show and LightboxForm.Hide.
  • I changed the Form’s Resize event code in the LightBoxForm class to avoid flickering: resizing the form within its Resize event actually trigger the Resize event again a second time which causes flickering.
    I simply modified the code to make the form totally transparent (opacity of 0) the first time the event is fired and assign it the expected opacity when the event handler in re-entered.

Samples
There are now 2 sample databases. Ech zip contains a Microsoft Access 2007 ACCDB file and its conversion to Access 2000-2003 MDB but please note that I have not been been able to test those in older version of Access and that form transparency doesn’t work in Operating Systems older than Windows 2000.

DownloadDownload TransparentLayer02.zip (95KB), recommended version
(improved, more flexible version, based on Rob’s updated article).

DownloadDownload TransparentLayer01.zip (82KB), original version
(simple code, based Rob’s original article).

Troubleshooting
If you are getting security warnings: make sure that you open the database from a Trusted Location or you will receive a security prompt.
If you don’t know how to do that, check these steps.
If the layer appears on top of the login form instead of behind: make sure that the top-most form has ist Modal properties set to Yes and the frmLightBox form has its modal property set to No.
If you improve on it, please let me know and I’ll post it here for all to find.

Entry Filed under  :  Database, MSAccess, Programming

7 Comments Add your own

  • 1. Fred Boer  |  May 8th, 2008 at 2:03 am

    Thanks for posting the demo!

  • 2. Edwin Blancovitch  |  May 8th, 2008 at 11:37 pm

    I have a small question, why a class module?

    It just work with the old module like in example #1

    Why complicate your life by using a class module, for my experience the purpose of the class module is to expose functionality of your project outside your project, but why to this simple code.

    I will appreciate if you really explain.

    By the way, great work, i will definetly use this in my projects.

  • 3. Edwin Blancovitch  |  May 8th, 2008 at 11:43 pm

    Im curious:

    what editor you use for the vba editor
    that shows the line numbers and that alternate row hightlight.

    It looks very nice and atractive to work on that :-)

    Please share . . .

  • 4. Renaud  |  May 9th, 2008 at 7:47 am

    @Edwin: I agree that the version with the Class is actually a bit more complex but it’s still quite educational and it nicely encapsulate the functionality. You end-up using only one global property (LightboxForm) to manage all layer functions.
    Whether you prefer one version or the other is up to you, that’s why I left both samples.

    Regarding the colour formatting of the code, I’m afraid that it just looks that way because I use a code syntax highlighter in my web pages…

  • 5. Edwin Blancovitch  |  May 13th, 2008 at 12:20 am

    Thanks for your answer, i was reading the comments on microsoft rss, and i think you are the appropiate guy so i can ask this question.

    I used to have code from lebans.com to highlight the current row in datasheet or continuos form, also to highlight the row based on some conditions, (the access embeed conditional format only supports 3)

    lebans created a solution for this, but now is outdated, i think you can revise the api’s and create a new solution(maybe give it to microsoft :-) )

    The thing is that if you look into excel you have a great conditional formatting options even with icons and all that stuff, but that doesnt exist for excel.

    What do you say, can you do it?

  • 6. Renaud  |  May 13th, 2008 at 10:00 am

    Hi Edwin. Thanks for the vote of confidence :-)
    I’ll look into Stephan Leban’s code and see if there is something to expand on there.
    The issue with taking row highlighting and conditional formatting further is that Access doesn’t expose a lot of its internal functionalities. One of the problems is that controls like textboxes are not really normal windows controls (with a few exceptions).
    These lightweight controls are rendered internally by Access as images on the form until the focus moves to them.
    The OnPaint event is also fairly limited and only exists at the form section level and not the control level.
    So extending Access’ behaviour in that regard is probably too hard to be worth the time, especially when you consider that whatever you do may be rendered useless or incompatible by the next version of Access.
    Also to consider is that when more features are needed, it is probably better and easier to just include managed components in your forms: with the Form Interop Toolkit you can use .Net controls in Access. It requires some work and it’s not as tightly integrated or as easy as I’d want but it’s possible.
    By doing that you could include just about anything in your forms, and you open your application to a world of more interesting controls than the limited ones provided in Access.
    I plan to make a series of articles on that subject in the next few weeks.

  • 7. Phil  |  May 16th, 2008 at 1:33 am

    Both options fade the whole screen on my Vista SP1 machine.

    Nice Gentoo logo placement

Leave a Comment

hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Most Recent Posts

Categories

Links