Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Access 2010 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2010 Programmer's Reference by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Jerry Dennison; ISBN: 978-0-470-59166-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2010 VBA Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 27th, 2012, 12:24 PM
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default Chapter 9 page 286 ?

Has anyone tried using the suggested code on page 286 ( EXTENDING VBA WITH APIs ). I have double-checked, and it's as it is in the book. Using a Breakpoint, it seems to run normally, but no icon appears on the form, ( it's a .png file ) I wondered if this was the cause. What is an .ico type file, and where can I find them ?
Reply With Quote
  #2 (permalink)  
Old October 27th, 2012, 03:03 PM
Authorized User
Points: 380, Level: 6
Points: 380, Level: 6 Points: 380, Level: 6 Points: 380, Level: 6
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Hi liamfitz,

I haven't tried it, but yes that is your problem the image needs to be an ico file type. You can convert your png to an ico file using http://www.convertico.com/.

Make sure the converted ico file is 16x16 pixels though.

HTH.

Malc.
Reply With Quote
  #3 (permalink)  
Old August 15th, 2013, 04:53 PM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default Having the same problem

Hi all, I am having the same problem as the previous poster liamfitz. I tried the suggestion posted by Malcolm Dixon with no success. Any other help would help.
Thanks. Bye the way. I have confirmed that my code is exactly as typed in the book.
Reply With Quote
  #4 (permalink)  
Old August 15th, 2013, 06:39 PM
gjgriffith's Avatar
Wrox Author
Points: 517, Level: 8
Points: 517, Level: 8 Points: 517, Level: 8 Points: 517, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: Boulder, CO
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Default Try this code...

Hello LiamFitz and GimmieKnowledge,

Thank you so much for reading the 'Microsoft Access 2010 Programmer's Reference' book and for posting your questions here. I saw the questions here and I wanted to follow up to see if I could help you guys solve your problems!

Ok, so right off, I should say that I personally did not write this chapter and am not intimately familiar with it, but I did have a chance to review both of your questions and pages 285-287 (that you mentioned) in the book. I also tested the code that was provided in the sample files for the book and I had to modify things slightly to make it work, but I WAS ABLE to get this to work after a bit of tweaking the sample code provided. So, a couple of things to mention right away:

1. An ICO (.ico) file is a standard "icon" file. That is how I tested this and I did not try it with a PNG file...so that may or may not work, I'm not sure, but you can always test it with my code below.

2. For the form to show a custom icon (in MS Access 2010), the form MUST BE A POP-UP form. If the form is just a tabbed document, it WILL NOT show the custom icon that can be loaded with this code.

*** So please be aware of those 2 items when reviewing this example. ***

So, as for my example, I just created a new database with a new form in it, and placed the code example from the book behind it, but again, I had to modify the original code sample slightly. Also, my code example (below) expects the ICO file to be at the "C:\Sample.ico" location on your computer, and I have included this sample icon with the example database (as an attachment in the form) so that you can copy it to your "C:\" drive and test this code out for yourself. The complete code for the form (that ended up working for me) was this code:

Code:
Option Explicit
Option Compare Database

#If Win64 = 1 And VBA7 = 1 Then

' Declare the 64-bit 'Load Image' function from the user32.dll
Private Declare PtrSafe Function LoadImage Lib "user32" Alias "LoadImageA" ( _
    ByVal hInst As LongPtr, _
    ByVal lpsz As String, _
    ByVal un1 As Long, _
    ByVal n1 As Long, _
    ByVal n2 As Long, _
    ByVal un2 As Long _
    ) As LongPtr

' Declare the 64-bit 'Send Message' function from the user32.dll
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hWnd As LongPtr, _
    ByVal wMsg As Long, _
    ByVal wParam As LongPtr, _
    LParam As Any _
    ) As Long
        
' Declare the 64-bit 'Format Message' function from the kernel32.dll
Private Declare PtrSafe Function FormatMessage Lib "kernel32" Alias "FormatMessageA" ( _
    ByVal dwFlags As Long, _
    lpSource As Long, _
    ByVal dwMessageId As Long, _
    ByVal dwLanguageId As Long, _
    ByVal lpBuffer As String, _
    ByVal nSize As Long, _
    Arguments As Any _
    ) As Long


#ElseIf VBA6 = 1 Then

' Declare the 32-bit 'Load Image' function from the user32.dll
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" ( _
    ByVal hInst As Long, _
    ByVal lpsz As String, _
    ByVal un1 As Long, _
    ByVal n1 As Long, _
    ByVal n2 As Long, _
    ByVal un2 As Long _
    ) As Long

' Declare the 32-bit 'Send Message' function from the user32.dll
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hWnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    LParam As Any _
    ) As Long

' Declare the 32-bit 'Format Message' function from the kernel32.dll
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" ( _
    ByVal dwFlags As Long, _
    lpSource As Long, _
    ByVal dwMessageId As Long, _
    ByVal dwLanguageId As Long, _
    ByVal lpBuffer As String, _
    ByVal nSize As Long, _
    Arguments As Any _
    ) As Long
    
#End If

    
Private Const FORMAT_MESSAGE_FROM_SYSTEM  As Long = &H1000
Private Const IMAGE_ICON                  As Long = 1 'Image type constants
Private Const LR_LOADFROMFILE             As Long = &H10 'un2 Flags

'Message parameters
Private Const WM_SETICON                  As Long = &H80
Private Const ICON_SMALL                  As Long = 0

'Default image size for the Access Titlebar
Private Const IMG_DEFAULT_HEIGHT          As Long = 16
Private Const IMG_DEFAULT_WIDTH           As Long = 16


Public Sub SetFormIcon(hWnd As Long, strIcon As String)
    
    Dim hIcon As Long
    Dim lngReturn As Long
    
    On Error Resume Next
    
    'Pass the strIcon parameter as the icon path
    hIcon = LoadImage(0, strIcon, IMAGE_ICON, IMG_DEFAULT_WIDTH, _
                    IMG_DEFAULT_HEIGHT, LR_LOADFROMFILE)
    
    'Now check for an error
    If hIcon <> 0 Then
        lngReturn = SendMessage(hWnd, WM_SETICON, ICON_SMALL, ByVal hIcon)
    Else
        'Display the error
        MsgBox "The last DLL error was: " & GetAPIErrorMessage(Err.LastDllError)
    End If
    
End Sub


Public Function GetAPIErrorMessage(lngError As Long) As String
    Dim strMessage As String
    Dim lngReturn  As Long
    Dim nSize      As Long

    strMessage = Space(256)
    nSize = Len(strMessage)
    lngReturn = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, _
                            lngError, 0, strMessage, nSize, 0)

    If lngReturn > 0 Then
        GetAPIErrorMessage = Replace(Left(strMessage, lngReturn), vbCrLf, "")
    Else
        GetAPIErrorMessage = "Error not found."
    End If
End Function


Private Sub Form_Load()
    SetFormIcon Me.hWnd, "C:\Sample.ico"
End Sub
So, once I ran this code with a Pop-up form, I didn't have any problems seeing the icon show up in the top-left corner of the form. You can download my example database and code for your own testing from here:
http://www.imaginethought.net/c/exam...013-8-15.accdb
And just remember to save the "Sample.ico" file (that is an attachment on the "frmSample" form in this database) to your "C:\Sample.ico" location. Also, be sure to enable the database when testing this, otherwise the VBA code will not run (...I guess that goes without saying though...).

Anyway, I really hope this helps, but if you have any other questions or need any other help with this, please just let me know. And thank you again for reading the 'Microsoft Access 2010 Programmer's Reference' book, we truly appreciate your readership!

Thanks again,
__________________
Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Microsoft Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference

*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->

Last edited by gjgriffith; August 16th, 2013 at 03:31 AM.. Reason: spelling
Reply With Quote
The Following User Says Thank You to gjgriffith For This Useful Post:
gimmieknowledge (August 21st, 2013)
  #5 (permalink)  
Old August 15th, 2013, 08:22 PM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default Thanks for the quick reply

Hey gjgriffith,

Let me play with this tonight and I will let you know how it works out for me.
Thanks
Reply With Quote
  #6 (permalink)  
Old August 15th, 2013, 09:09 PM
gjgriffith's Avatar
Wrox Author
Points: 517, Level: 8
Points: 517, Level: 8 Points: 517, Level: 8 Points: 517, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: Boulder, CO
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Default Let me know if there is anything else I can do to help!

Hello GimmieKnowledge,

Sounds great - I'm glad to hear you got my reply here. Definitely play around with it and if you have any other questions, please feel free to post here and I will do my best to help out. And thank again for reading the Access 2010 Programmer's Reference - we truly appreciate your readership!!

Thanks again,
__________________
Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Microsoft Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference

*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->
Reply With Quote
  #7 (permalink)  
Old August 16th, 2013, 02:46 AM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default Hey gjgriffith

Been up all night with this. It works perfectly. I learned a lot stepping through your code. Too bad it is not in the chapter download. Thanks for your help.
Reply With Quote
  #8 (permalink)  
Old August 16th, 2013, 03:43 AM
gjgriffith's Avatar
Wrox Author
Points: 517, Level: 8
Points: 517, Level: 8 Points: 517, Level: 8 Points: 517, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: Boulder, CO
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Smile Awesome - glad it worked for you!

Hello Gimmie,

Great - I'm so glad to hear that you were able to get this to work and I'm pleased that you felt my example was helpful - the kind words are appreciated!

True that it is unfortunate that the code in the book isn't as granular as this particular task, but now that you've asked the question, other people searching the internet will find this information thanks to you guys!!! So thank you again for posting your question here, it was definitely a good one!

And if there is anything else we can do to help, please post more questions in the future!

Thanks again,
__________________
Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Microsoft Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference

*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 Page 55 jmazzeo BOOK: Beginning ASP.NET 4 : in C# and VB 2 March 19th, 2012 09:56 AM
Page 286, downloading s/binary/images eoswins BOOK: Beginning Android Application Development 6 December 28th, 2011 07:53 PM
Chapter 9 - Page 301 Try it Out demac3 BOOK: Beginning ASP.NET 4 : in C# and VB 7 December 9th, 2010 02:47 PM
Chapter 8 User Controls: Try It Out Pages 283-286 epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 October 11th, 2009 11:53 AM
chapter 2 - page 41 problem creating the page.. jorjiana BOOK: Beginning Oracle Application Express ISBN: 9780470388372 2 August 22nd, 2009 04:25 AM



All times are GMT -4. The time now is 07:52 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.