By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,234 Members | 1,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,234 IT Pros & Developers. It's quick & easy.

Problem on incorporting code from the Access 2000 Developer's Handbook

P: n/a
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
Nov 12 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
TC
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" <u0***@usa.net> wrote in message
news:8a**************************@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 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

Nov 12 '05 #2

P: n/a
TC
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" <u0***@usa.net> wrote in message
news:8a*************************@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" <te*********@mps.co.uk> wrote in message

news:<bj**********@newsreaderg1.core.theplanet.net >...
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" <u0***@usa.net> wrote in message
news:8a**************************@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 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

Nov 12 '05 #3

P: n/a
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" <u0***@usa.net> wrote in message
news:8a*************************@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" <te*********@mps.co.uk> wrote in message

news:<bj**********@newsreaderg1.core.theplanet.net >...
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" <u0***@usa.net> wrote in message
news:8a**************************@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 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

Nov 12 '05 #4

P: n/a
"Uttam" <u0***@usa.net> wrote...
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.


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.

Nov 12 '05 #5

P: n/a
TC
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" <u0***@usa.net> wrote in message
news:8a**************************@posting.google.c om...
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>...
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" <u0***@usa.net> wrote in message
news:8a*************************@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" <te*********@mps.co.uk> wrote in message

news:<bj**********@newsreaderg1.core.theplanet.net >...
> 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" <u0***@usa.net> wrote in message
> news:8a**************************@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 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

Nov 12 '05 #6

P: n/a
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>...
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" <u0***@usa.net> wrote in message
news:8a**************************@posting.google.c om...
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>...
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" <u0***@usa.net> wrote in message
news:8a*************************@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" <te*********@mps.co.uk> wrote in message news:<bj**********@newsreaderg1.core.theplanet.net >... > > 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" <u0***@usa.net> wrote in message
> > news:8a**************************@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 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

Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.