Problem on incorporting code from the Access 2000 Developer's Handbook | | |
Hello,
I am using the code from Chapter 17 specifically the code from the
font frmListFonts in my application.
I have taken care to copy all the relevant modules / class modules
into the respective files / folders etc. Nevertheless, I get the
following error when I start my application:
Compile error; Sub or Function not defined
This error is displayed on the following line of which "GetDC" is
selected.
hdc = GetDC(HWND_DESKTOP)
I have all the 7 Class Modules from Ch17.mdb as also all the Modules.
These were exported from Ch17.mdb into a file and later imported into
my application.
I am unable to fathom what is going wrong here - can someone help?
Thanks in advance.
Uttam | | | | re: Problem on incorporting code from the Access 2000 Developer's Handbook
I don't have that book, but, GetDC is a so-called "windows API". It must be
defined in a DECLARE statement. See if you can find such a statement. If you
can't, that is the problem. If you can, try making it say PUBLIC DECLARE ...
(not PRIVATE DECLARE ...).
HTH,
TC
"Uttam" <u0107@usa.net> wrote in message
news:8a9f572f.0309112046.34cc3146@posting.google.c om...[color=blue]
> Hello,
>
> I am using the code from Chapter 17 specifically the code from the
> font frmListFonts in my application.
>
> I have taken care to copy all the relevant modules / class modules
> into the respective files / folders etc. Nevertheless, I get the
> following error when I start my application:
>
> Compile error; Sub or Function not defined
>
> This error is displayed on the following line of which "GetDC" is
> selected.
>
> hdc = GetDC(HWND_DESKTOP)
>
> I have all the 7 Class Modules from Ch17.mdb as also all the Modules.
> These were exported from Ch17.mdb into a file and later imported into
> my application.
>
> I am unable to fathom what is going wrong here - can someone help?
>
> Thanks in advance.
>
> Uttam[/color] | | | | re: Problem on incorporting code from the Access 2000 Developer's Handbook
Try posting the whole content of the module that gets the error. And be sure
to repeat exactly what the error is, & on what line it occurs.
HTH,
TC
"Uttam" <u0107@usa.net> wrote in message
news:8a9f572f.0309131831.77c99d8@posting.google.co m...[color=blue]
> Hello,
>
> I tried Terry's solution. The declarations section does contain the
> code as suggested by Terry. Nevertheless the problem still occurs.
>
> One thing I discovered was that when running the example in the book,
> there is one reference to Microsoft Forms 2.0 Object which I installed
> explicitly. The list of references in my app now match that in
> Chapter 17.
>
> Still I get the problem.
>
> Any other suggestions please?
>
> Thanks
>
> Uttam
>
>
> "Terry Kreft" <terry.kreft@mps.co.uk> wrote in message[/color]
news:<bjrssl$67c$1@newsreaderg1.core.theplanet.net >...[color=blue][color=green]
> > Well the problem is most likely that you haven't declared GetDC or you
> > haven't declared HWND_DESKTOP or they aren't in scope
> >
> > To check which it is
> > Open the code window
> > put the cursor inside teh word GetDC
> > Press Shift-F2 on the keyboard
> >
> > If you've declared it and it is in scope the cursor will jump to the
> > declaration
> >
> > Then do the same with HWND_DESKTOP
> >
> > Once you know which is missinig it is easy to declare them.
> >
> > Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As
> > Long) As Long
> > Private Const HWND_DESKTOP = 0
> >
> > both of which go in the declarations section of the module.
> >
> > Terry
> >
> > "Uttam" <u0107@usa.net> wrote in message
> > news:8a9f572f.0309112046.34cc3146@posting.google.c om...[color=darkred]
> > > Hello,
> > >
> > > I am using the code from Chapter 17 specifically the code from the
> > > font frmListFonts in my application.
> > >
> > > I have taken care to copy all the relevant modules / class modules
> > > into the respective files / folders etc. Nevertheless, I get the
> > > following error when I start my application:
> > >
> > > Compile error; Sub or Function not defined
> > >
> > > This error is displayed on the following line of which "GetDC" is
> > > selected.
> > >
> > > hdc = GetDC(HWND_DESKTOP)
> > >
> > > I have all the 7 Class Modules from Ch17.mdb as also all the Modules.
> > > These were exported from Ch17.mdb into a file and later imported into
> > > my application.
> > >
> > > I am unable to fathom what is going wrong here - can someone help?
> > >
> > > Thanks in advance.
> > >
> > > Uttam[/color][/color][/color] | | | | re: Problem on incorporting code from the Access 2000 Developer's Handbook
The important fact to realize -- ACCESS controls do not have HWNDs, except a
few of them do when they have the focus. Forms^3 (Forms 2.0) controls never
have HWNDs, at all. The book explains these facts.
--
MichKa [MS]
This posting is provided "AS IS" with
no warranties, and confers no rights.
"Uttam" <u0107@usa.net> wrote in message
news:8a9f572f.0309131831.77c99d8@posting.google.co m...[color=blue]
> Hello,
>
> I tried Terry's solution. The declarations section does contain the
> code as suggested by Terry. Nevertheless the problem still occurs.
>
> One thing I discovered was that when running the example in the book,
> there is one reference to Microsoft Forms 2.0 Object which I installed
> explicitly. The list of references in my app now match that in
> Chapter 17.
>
> Still I get the problem.
>
> Any other suggestions please?
>
> Thanks
>
> Uttam
>
>
> "Terry Kreft" <terry.kreft@mps.co.uk> wrote in message[/color]
news:<bjrssl$67c$1@newsreaderg1.core.theplanet.net >...[color=blue][color=green]
> > Well the problem is most likely that you haven't declared GetDC or you
> > haven't declared HWND_DESKTOP or they aren't in scope
> >
> > To check which it is
> > Open the code window
> > put the cursor inside teh word GetDC
> > Press Shift-F2 on the keyboard
> >
> > If you've declared it and it is in scope the cursor will jump to the
> > declaration
> >
> > Then do the same with HWND_DESKTOP
> >
> > Once you know which is missinig it is easy to declare them.
> >
> > Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As
> > Long) As Long
> > Private Const HWND_DESKTOP = 0
> >
> > both of which go in the declarations section of the module.
> >
> > Terry
> >
> > "Uttam" <u0107@usa.net> wrote in message
> > news:8a9f572f.0309112046.34cc3146@posting.google.c om...[color=darkred]
> > > Hello,
> > >
> > > I am using the code from Chapter 17 specifically the code from the
> > > font frmListFonts in my application.
> > >
> > > I have taken care to copy all the relevant modules / class modules
> > > into the respective files / folders etc. Nevertheless, I get the
> > > following error when I start my application:
> > >
> > > Compile error; Sub or Function not defined
> > >
> > > This error is displayed on the following line of which "GetDC" is
> > > selected.
> > >
> > > hdc = GetDC(HWND_DESKTOP)
> > >
> > > I have all the 7 Class Modules from Ch17.mdb as also all the Modules.
> > > These were exported from Ch17.mdb into a file and later imported into
> > > my application.
> > >
> > > I am unable to fathom what is going wrong here - can someone help?
> > >
> > > Thanks in advance.
> > >
> > > Uttam[/color][/color][/color] | | | | re: Problem on incorporting code from the Access 2000 Developer's Handbook
"Uttam" <u0107@usa.net> wrote...
[color=blue]
> Thanks Terry for offering to help. Here goes:
>
> I have marked the specific line where the error occurs with
>
> "========>"
>
> On that line the text "GetDC" is highlighted with a pop up message
> which says:
>
> Compile Error. Sub or function not defined.[/color]
UM... Your Declare statement for GetDC is marked "Private" and its in
another module. Thus as far as your code is concerned, its not defined.
--
MichKa [MS]
This posting is provided "AS IS" with
no warranties, and confers no rights. | | | | re: Problem on incorporting code from the Access 2000 Developer's Handbook
Hi Uttam
I'm TC, not Terry!
As the other respondent said, in Module1, you have "Private Declare..."
throughout. The Private keyword menas that each of those declarations is
only visible to code within Module1. It is not visible within any other
module. Try changing all those "Private"s to "Public"s, and try again (ie.
Public Declare...).
HTH,
TC
"Uttam" <u0107@usa.net> wrote in message
news:8a9f572f.0309141724.29a82140@posting.google.c om...[color=blue]
> Thanks Terry for offering to help. Here goes:
>
> I have marked the specific line where the error occurs with
>
> "========>"
>
> On that line the text "GetDC" is highlighted with a pop up message
> which says:
>
> Compile Error. Sub or function not defined.
>
>
>
> Private Sub New_Font_List_Combo_Load()
> '---------------------------------
>
>
>
> '
> ' This function fills in the array of suggested TrueType font
> sizes.
> ' It also fills in the array holding all the information about the
> ' available fonts. If the first font is a raster font, it gets the
> ' available font sizes for that font.
> '
> Dim hdc As Long
>
> On Error GoTo HandleErrors
>
> mintCountTTSizes = 16
> maintTTSizes = Array(8, 9, 10, 11, 12, 14, 16, _
> 18, 20, 22, 24, 26, 28, 36, 48, 72)
> =======> hdc = GetDC(HWND_DESKTOP)
> If hdc <> 0 Then
> ' Get the number of fonts.
> mlngCountFonts = adh_accGetFontCount(hdc)
> ' If there are fonts, dimension the array
> ' to be the right size.
> If mlngCountFonts > 0 Then
> ReDim mafiFonts(0 To mlngCountFonts - 1)
> ' Fill mafiFonts() with the font names.
> mlngCountFonts = adh_accGetFontList(hdc, mafiFonts())
> End If
> <snip><snip><snip><snip><snip><snip><snip><snip><s nip><snip>
>
>
> In Module1 where all my global variables and my commonly called sub
> routines are coded, I have the following code:
>
>
>
>
> Option Explicit
>
> ' From Access 2000 Developer's Handbook, Volume I
> ' by Getz, Litwin, and Gilbert. (Sybex)
> ' Copyright 1999. All rights reserved.
>
> ' This module contains replacements for the font
> ' handling procedures provided by Access 97 internally.
> ' Because Access 2000 doesn't provide these procedures
> ' you can use these replacements for any existing
> ' code. You might want to investigate the ScreenInfo
> ' object for future development, as it provides
> ' this same information in a simpler manner.
>
> ' In this module:
> ' adh_accGetFontCount
> ' adh_accGetFontList
> ' adh_accGetSizeCount
> ' adh_accGetSizeList
> '
> ' Requires:
> ' basCommon
> ' basFontCommon
>
> ' Indicate that a parameter for Quicksort is missing.
> Private Const dhcMissing = -2
>
> ' ================
> ' API Declarations
> ' ================
> Private Const LOGPIXELSX = 88 ' Logical pixels/inch in X
> Private Const LOGPIXELSY = 90
> Private Const HWND_DESKTOP = 0
> Private Const LF_FACESIZE = 32
> Private Const DEFAULT_CHARSET = 1
>
> Private Declare Function GetDeviceCaps _
> Lib "gdi32" _
> (ByVal hdc As Long, ByVal nIndex As Long) As Long
>
> Private Declare Function MulDiv _
> Lib "kernel32" _
> (ByVal nNumber As Long, ByVal nNumerator As Long, _
> ByVal nDenominator As Long) As Long
>
> Private Declare Function EnumFontFamilies _
> Lib "gdi32" Alias "EnumFontFamiliesA" _
> (ByVal hdc As Long, ByVal lpszFamily As String, _
> ByVal lpEnumFontFamProc As Long, ByVal lParam As Long) As Long
>
> Private Declare Function CreateFontIndirect _
> Lib "gdi32" Alias "CreateFontIndirectA" _
> (lpLogFont As LOGFONT) As Long
>
> Private Declare Function GetDC _
> Lib "USER32" _
> (ByVal hWnd As Long) As Long
>
> Private Declare Function ReleaseDC _
> Lib "USER32" _
> (ByVal hWnd As Long, ByVal hdc As Long) As Long
>
>
> *-*-*-*-*-*-*-*-*-*-*
>
> As you can see, I have GetDC defined above.
>
> Just to explain, I have copied this "as is" from the book with only
> the variables names of the drop down box changed to match what is on
> my application.
>
> Thanks once again.
>
> Cheers!
>
> Uttam
>
> ================
>
>
>
>
> "TC" <a@b.c.d> wrote in message news:<1063518214.847834@teuthos>...[color=green]
> > Try posting the whole content of the module that gets the error. And be[/color][/color]
sure[color=blue][color=green]
> > to repeat exactly what the error is, & on what line it occurs.
> >
> > HTH,
> > TC
> >
> >
> > "Uttam" <u0107@usa.net> wrote in message
> > news:8a9f572f.0309131831.77c99d8@posting.google.co m...[color=darkred]
> > > Hello,
> > >
> > > I tried Terry's solution. The declarations section does contain the
> > > code as suggested by Terry. Nevertheless the problem still occurs.
> > >
> > > One thing I discovered was that when running the example in the book,
> > > there is one reference to Microsoft Forms 2.0 Object which I installed
> > > explicitly. The list of references in my app now match that in
> > > Chapter 17.
> > >
> > > Still I get the problem.
> > >
> > > Any other suggestions please?
> > >
> > > Thanks
> > >
> > > Uttam
> > >
> > >
> > > "Terry Kreft" <terry.kreft@mps.co.uk> wrote in message[/color]
> > news:<bjrssl$67c$1@newsreaderg1.core.theplanet.net >...[color=darkred]
> > > > Well the problem is most likely that you haven't declared GetDC or[/color][/color][/color]
you[color=blue][color=green][color=darkred]
> > > > haven't declared HWND_DESKTOP or they aren't in scope
> > > >
> > > > To check which it is
> > > > Open the code window
> > > > put the cursor inside teh word GetDC
> > > > Press Shift-F2 on the keyboard
> > > >
> > > > If you've declared it and it is in scope the cursor will jump to the
> > > > declaration
> > > >
> > > > Then do the same with HWND_DESKTOP
> > > >
> > > > Once you know which is missinig it is easy to declare them.
> > > >
> > > > Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal[/color][/color][/color]
hwnd As[color=blue][color=green][color=darkred]
> > > > Long) As Long
> > > > Private Const HWND_DESKTOP = 0
> > > >
> > > > both of which go in the declarations section of the module.
> > > >
> > > > Terry
> > > >
> > > > "Uttam" <u0107@usa.net> wrote in message
> > > > news:8a9f572f.0309112046.34cc3146@posting.google.c om...
> > > > > Hello,
> > > > >
> > > > > I am using the code from Chapter 17 specifically the code from the
> > > > > font frmListFonts in my application.
> > > > >
> > > > > I have taken care to copy all the relevant modules / class modules
> > > > > into the respective files / folders etc. Nevertheless, I get the
> > > > > following error when I start my application:
> > > > >
> > > > > Compile error; Sub or Function not defined
> > > > >
> > > > > This error is displayed on the following line of which "GetDC" is
> > > > > selected.
> > > > >
> > > > > hdc = GetDC(HWND_DESKTOP)
> > > > >
> > > > > I have all the 7 Class Modules from Ch17.mdb as also all the[/color][/color][/color]
Modules.[color=blue][color=green][color=darkred]
> > > > > These were exported from Ch17.mdb into a file and later imported[/color][/color][/color]
into[color=blue][color=green][color=darkred]
> > > > > my application.
> > > > >
> > > > > I am unable to fathom what is going wrong here - can someone help?
> > > > >
> > > > > Thanks in advance.
> > > > >
> > > > > Uttam[/color][/color][/color] | | | | re: Problem on incorporting code from the Access 2000 Developer's Handbook
I owe you an apology TC.
Converting to Public certainly works - now I have to grapple with some
other logical errors, which I will be able to solve by myself.
To all who responded to my query - THANK YOU all!
Cheers!
Uttam
================
"TC" <a@b.c.d> wrote in message news:<1063615643.882313@teuthos>...[color=blue]
> Hi Uttam
>
> I'm TC, not Terry!
>
> As the other respondent said, in Module1, you have "Private Declare..."
> throughout. The Private keyword menas that each of those declarations is
> only visible to code within Module1. It is not visible within any other
> module. Try changing all those "Private"s to "Public"s, and try again (ie.
> Public Declare...).
>
> HTH,
> TC
>
>
>
> "Uttam" <u0107@usa.net> wrote in message
> news:8a9f572f.0309141724.29a82140@posting.google.c om...[color=green]
> > Thanks Terry for offering to help. Here goes:
> >
> > I have marked the specific line where the error occurs with
> >
> > "========>"
> >
> > On that line the text "GetDC" is highlighted with a pop up message
> > which says:
> >
> > Compile Error. Sub or function not defined.
> >
> >
> >
> > Private Sub New_Font_List_Combo_Load()
> > '---------------------------------
> >
> >
> >
> > '
> > ' This function fills in the array of suggested TrueType font
> > sizes.
> > ' It also fills in the array holding all the information about the
> > ' available fonts. If the first font is a raster font, it gets the
> > ' available font sizes for that font.
> > '
> > Dim hdc As Long
> >
> > On Error GoTo HandleErrors
> >
> > mintCountTTSizes = 16
> > maintTTSizes = Array(8, 9, 10, 11, 12, 14, 16, _
> > 18, 20, 22, 24, 26, 28, 36, 48, 72)
> > =======> hdc = GetDC(HWND_DESKTOP)
> > If hdc <> 0 Then
> > ' Get the number of fonts.
> > mlngCountFonts = adh_accGetFontCount(hdc)
> > ' If there are fonts, dimension the array
> > ' to be the right size.
> > If mlngCountFonts > 0 Then
> > ReDim mafiFonts(0 To mlngCountFonts - 1)
> > ' Fill mafiFonts() with the font names.
> > mlngCountFonts = adh_accGetFontList(hdc, mafiFonts())
> > End If
> > <snip><snip><snip><snip><snip><snip><snip><snip><s nip><snip>
> >
> >
> > In Module1 where all my global variables and my commonly called sub
> > routines are coded, I have the following code:
> >
> >
> >
> >
> > Option Explicit
> >
> > ' From Access 2000 Developer's Handbook, Volume I
> > ' by Getz, Litwin, and Gilbert. (Sybex)
> > ' Copyright 1999. All rights reserved.
> >
> > ' This module contains replacements for the font
> > ' handling procedures provided by Access 97 internally.
> > ' Because Access 2000 doesn't provide these procedures
> > ' you can use these replacements for any existing
> > ' code. You might want to investigate the ScreenInfo
> > ' object for future development, as it provides
> > ' this same information in a simpler manner.
> >
> > ' In this module:
> > ' adh_accGetFontCount
> > ' adh_accGetFontList
> > ' adh_accGetSizeCount
> > ' adh_accGetSizeList
> > '
> > ' Requires:
> > ' basCommon
> > ' basFontCommon
> >
> > ' Indicate that a parameter for Quicksort is missing.
> > Private Const dhcMissing = -2
> >
> > ' ================
> > ' API Declarations
> > ' ================
> > Private Const LOGPIXELSX = 88 ' Logical pixels/inch in X
> > Private Const LOGPIXELSY = 90
> > Private Const HWND_DESKTOP = 0
> > Private Const LF_FACESIZE = 32
> > Private Const DEFAULT_CHARSET = 1
> >
> > Private Declare Function GetDeviceCaps _
> > Lib "gdi32" _
> > (ByVal hdc As Long, ByVal nIndex As Long) As Long
> >
> > Private Declare Function MulDiv _
> > Lib "kernel32" _
> > (ByVal nNumber As Long, ByVal nNumerator As Long, _
> > ByVal nDenominator As Long) As Long
> >
> > Private Declare Function EnumFontFamilies _
> > Lib "gdi32" Alias "EnumFontFamiliesA" _
> > (ByVal hdc As Long, ByVal lpszFamily As String, _
> > ByVal lpEnumFontFamProc As Long, ByVal lParam As Long) As Long
> >
> > Private Declare Function CreateFontIndirect _
> > Lib "gdi32" Alias "CreateFontIndirectA" _
> > (lpLogFont As LOGFONT) As Long
> >
> > Private Declare Function GetDC _
> > Lib "USER32" _
> > (ByVal hWnd As Long) As Long
> >
> > Private Declare Function ReleaseDC _
> > Lib "USER32" _
> > (ByVal hWnd As Long, ByVal hdc As Long) As Long
> >
> >
> > *-*-*-*-*-*-*-*-*-*-*
> >
> > As you can see, I have GetDC defined above.
> >
> > Just to explain, I have copied this "as is" from the book with only
> > the variables names of the drop down box changed to match what is on
> > my application.
> >
> > Thanks once again.
> >
> > Cheers!
> >
> > Uttam
> >
> > ================
> >
> >
> >
> >
> > "TC" <a@b.c.d> wrote in message news:<1063518214.847834@teuthos>...[color=darkred]
> > > Try posting the whole content of the module that gets the error. And be[/color][/color]
> sure[color=green][color=darkred]
> > > to repeat exactly what the error is, & on what line it occurs.
> > >
> > > HTH,
> > > TC
> > >
> > >
> > > "Uttam" <u0107@usa.net> wrote in message
> > > news:8a9f572f.0309131831.77c99d8@posting.google.co m...
> > > > Hello,
> > > >
> > > > I tried Terry's solution. The declarations section does contain the
> > > > code as suggested by Terry. Nevertheless the problem still occurs.
> > > >
> > > > One thing I discovered was that when running the example in the book,
> > > > there is one reference to Microsoft Forms 2.0 Object which I installed
> > > > explicitly. The list of references in my app now match that in
> > > > Chapter 17.
> > > >
> > > > Still I get the problem.
> > > >
> > > > Any other suggestions please?
> > > >
> > > > Thanks
> > > >
> > > > Uttam
> > > >
> > > >
> > > > "Terry Kreft" <terry.kreft@mps.co.uk> wrote in message[/color][/color]
> news:<bjrssl$67c$1@newsreaderg1.core.theplanet.net >...[color=green][color=darkred]
> > > > > Well the problem is most likely that you haven't declared GetDC or[/color][/color]
> you[color=green][color=darkred]
> > > > > haven't declared HWND_DESKTOP or they aren't in scope
> > > > >
> > > > > To check which it is
> > > > > Open the code window
> > > > > put the cursor inside teh word GetDC
> > > > > Press Shift-F2 on the keyboard
> > > > >
> > > > > If you've declared it and it is in scope the cursor will jump to the
> > > > > declaration
> > > > >
> > > > > Then do the same with HWND_DESKTOP
> > > > >
> > > > > Once you know which is missinig it is easy to declare them.
> > > > >
> > > > > Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal[/color][/color]
> hwnd As[color=green][color=darkred]
> > > > > Long) As Long
> > > > > Private Const HWND_DESKTOP = 0
> > > > >
> > > > > both of which go in the declarations section of the module.
> > > > >
> > > > > Terry
> > > > >
> > > > > "Uttam" <u0107@usa.net> wrote in message
> > > > > news:8a9f572f.0309112046.34cc3146@posting.google.c om...
> > > > > > Hello,
> > > > > >
> > > > > > I am using the code from Chapter 17 specifically the code from the
> > > > > > font frmListFonts in my application.
> > > > > >
> > > > > > I have taken care to copy all the relevant modules / class modules
> > > > > > into the respective files / folders etc. Nevertheless, I get the
> > > > > > following error when I start my application:
> > > > > >
> > > > > > Compile error; Sub or Function not defined
> > > > > >
> > > > > > This error is displayed on the following line of which "GetDC" is
> > > > > > selected.
> > > > > >
> > > > > > hdc = GetDC(HWND_DESKTOP)
> > > > > >
> > > > > > I have all the 7 Class Modules from Ch17.mdb as also all the[/color][/color]
> Modules.[color=green][color=darkred]
> > > > > > These were exported from Ch17.mdb into a file and later imported[/color][/color]
> into[color=green][color=darkred]
> > > > > > my application.
> > > > > >
> > > > > > I am unable to fathom what is going wrong here - can someone help?
> > > > > >
> > > > > > Thanks in advance.
> > > > > >
> > > > > > Uttam[/color][/color][/color] |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,439 network members.
|