Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    109

    How to use MsgBox Icons on a Custom Form

    Hi,



    I'm trying to roll my own custom message box functionality, mainly because I want to implement a time-out ability, so after XX seconds the form will disappear and return the response that was the "default" response.

    I've already created an extended message box function which leverages the built-in MsgBox, and through API's I can change the button text to what I want, and even the color of the message text. This is somewhat complex and can be buggy, so I've decided to build a custom form that I can use for a MsgBox.

    First challenge is to display the icons from a normal MsgBox, which respond to the Style argument (vbQuestion, vbExclamation, etc.).

    Is there any way to find those icons/images and use them in my form?

    Thanks...

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    883
    screen cap them and use an image control
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    9,171
    Use image control yes, but 1000's of these images are probably still available and if you're going to do a lot of customization it might be worth it to grab some. I must have 130 folders, some with as many as 160 subfolders, every folder with anywhere from 12 to 30 files. A search for just *.ico returns about 3000 images. What's the bet that there is no yellow warning sign though? You will have to embed your images or deal with the hassle of distribution if you don't.

    EDIT - Actually, they are there.
    Besides, you'd be able to have a bit of fun with it...

    Click image for larger version. 

Name:	CustMsgBox.jpg 
Views:	41 
Size:	17.3 KB 
ID:	45476
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  4. #4
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,922
    See if any of the attached GIF/PNG images are any use to you. I use these (& others) in my own custom message forms
    Attached Files Attached Files
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    2,486
    Here is a timed message box replacement with custom buttons that I've been using for many years.
    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    9,171
    I presume that is supposed to be integrated into a db somehow? As it is, it doesn't do much? By that I mean it just closes in the open event. Will have to review your notes about icon transparency as I don't think I'm familiar with the issue.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    2,486
    Yes, you need to import the form and module in your app then call it similar to the msgbox, here is one example I use for a shut-down message (it counts down from 5 seconds-last argument):
    Code:
    Public Function vcCheckForShutDown()
    If DLookup("[Shutdown]", "[usysShutDown]") = True And DLookup("[Initiator]", "[usysShutDown]") <> fOSUserName() Then
        'initiate shut-down
        'display message
        MBox "Admin message from " & DLookup("[InitiatedBy]", "[qryShutDownMessage]") & ": " & vbCrLf & DLookup("[MessageDisplayed]", "[qryShutDownMessage]") & ". ", vbCritical + vbExclamation, "Admin Message", , , , , 5
        On Error Resume Next
        DoCmd.Quit acQuitSaveAll
    End If
    End Function
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    109
    Thanks for all the replies so far. I was hoping for a way to show the standard Access MsgBox icons on my custom form using some shortcut syntax, but embedding images in image controls then making the appropriate one visible at run-time works also. Thanks Colin for the sample pictures.

    Currently I'm using a TextBox with transparent border and back style to hold my message, instead of a Label control. I did this because a locked TextBox will show the content similar to a Label control, with the additional benefit of being able to select and copy the message if desired. I believe you can NOT do that with a label, right?

    Next challenge is to make the TextBox size a bit more dynamic, so like a regular MsgBox, the form can expand horizontally and vertically to accommodate longer messages. I'm already sizing the form based on the TxtBox width & height. So based on message length (and maybe font size), is there an easy way to resize the TxtBox in VBA? I'm looking for one with no scroll bars, just want to be able to size the width & height to known maximums based on how much text is to be displayed.

    Can't use TxtBox.SizeToFit command as that only works in design mode. I can use the .Move command to size it at run-time, but need to figure out how to calculate the width/height numbers from the text first.

    Any ideas how to do this? Thanks...

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    2,486
    Have you looked at my sample? It works in both 32 and 64 bits version and has all (or most) of the features you describe in your original post (timer, custom captions, custom icons, etc.). And it is very easy to use, similar to the native msgbox....
    Cheers,

  10. #10
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,922
    I am also wondering whether you are trying to reinvent the wheel.
    Suggest you have a look at my Attention Seeking database which includes a formatted message box and customised message forms.
    Also consider the Enhanced Message Box by Cypris.

    BTW the standard message box icons are available as part of the Shell32.dll and imageres,dll libraries:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	25 
Size:	33.4 KB 
ID:	45493

    Hope that helps
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  11. #11
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    109
    Thanks @Gicu. Tried to get your code to work, but it will not compile (I have a 64-bit PC and 64-bit Office installed). I replaced all of the APIs with PtrSafe versions, and changed some declared Long variables to LongPtr as needed. In
    Code:
    Private Function fAutoSizeTextBoxM(Ctl As Control) As RECT
    , I also get error executing the statement
    Code:
    lngIC = apiCreateIC("DISPLAY", vbNullString, vbNullString, vbNullString)
    Where the last vbNullString is highlighted when trying to compile. That last variable should be of type DEVMODE according to the API declaration.
    There are a few more like this. I had to make some of the TYPE declarations public and move them to the module so that they would work. I'm stuck, so I just gave up. But thanks for the suggestion.

  12. #12
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    109
    Colin, thanks for your comments and suggestions. I looked at Cypris' database and code, and it looks pretty amazing, but quite complex. I will think about using this. Haven't had time yet to look at your own project/code.

    As far as why reinvent the wheel? I didn't find that particular wheel until the last answers to this thread. The searching I did did not yield those results.

    Also, I started out with a simpler requirement of popping up a Font-picker dialog. Existing font dialogs did not seem satisfactory. My requirement was to "maybe" pick a font, or "maybe" pick a font size, or perhaps both. I'm using this to use with a Word mail-merge. So I wanted to be able to change the font size of a selection without changing the font itself if desired. Or maybe change just the font name without changing the size. My code is stored in Access tables, so I need to put in some codes in the text which would be resolved in the Word Merge part of the code. So my pop-up box has 2 combos, one for fonts and one for sizes. Both default to nothing chosen. When user finally choses what they want, I end up with something like this in my boilerplate text:
    "Now is the time for all <font;name;size>good</font> men..." This is then updated into the boilerplate text as store in Access. During the Word mailmerge, those codes are found and resolved in the Word document.

    Then, I decided to enhance my PopUp form and allow it to be a MsgBox replacement also, which is what I'm working on now. So depending on what I send in my open args when I open the form modally, it will be a font picker or an enhanced MsgBox.

    I've already got most of the functionality I need including custom button labels and colored text. The final thing is to be able to auto-resize the text box I'm using in case of long message text. If the text is too long to fit in the TxtBox, I widen it a bit and make it as tall as needed within reason, which mimics the standard MsgBox behavior with long messages. I found code to use WizHook functionality to get the text length/height from the TxtBox text (given the font attached to the TxtBox), but can't quite figure out how to figure out how many lines of text will fit in the txtBox given it's width and height. That seems to be the stopping point right now.

    Also, is there an easy way you know of to get the desired standard icon out of the DLL you mentioned? I'm familiar with using it in design mode, but can that DLL be used at run-time with VBA? If not, your suggestion of using custom images will suffice.

    Thanks...

  13. #13
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,922
    Suggest you do look at my Attention Seeking database. For example a customised message form using rich text:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	19 
Size:	26.7 KB 
ID:	45509

    The easiest way of extracting an icon from a DLL file is probably to use a utility like Icon extract
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  14. #14
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    883
    Quote Originally Posted by isladogs View Post

    The easiest way of extracting an icon from a DLL file is probably to use a utility like Icon extract
    Thats a keeper.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    2,486
    Please try these two files, both (32 and 64) bit versions are working OK for me.
    Cheers,
    Vlad
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Icons are squashed
    By sifuhall in forum Forms
    Replies: 1
    Last Post: 05-22-2018, 11:39 AM
  2. Custom button captions msgbox
    By Ruegen in forum Access
    Replies: 2
    Last Post: 11-20-2013, 03:59 PM
  3. Desktop Icons
    By Neil Bingham in forum Access
    Replies: 1
    Last Post: 05-12-2011, 10:29 AM
  4. Custom MsgBox
    By roccoIT in forum Programming
    Replies: 3
    Last Post: 07-06-2010, 10:43 AM
  5. Button Icons and MSG Box Icons
    By Mclaren in forum Programming
    Replies: 6
    Last Post: 06-22-2010, 11:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums