Difference between Form's Class Module and Class Module

  • Thread starter tobesurveyor via AccessMonster.com
  • Start date
T

tobesurveyor via AccessMonster.com

Is there a difference between a form's class module and just a class module?


I am using this code found under the www.mvps.com to choose a folder. I
placed the code under a new class module and when I went to compile it, it
gives me an error stating "Method or data member not found"

Any Help would be great. Thanks,
Chris

Here is the code...

Public Function BrowseForFolderByPath(sSelPath As String) As String

Dim BI As BROWSEINFO
Dim pidl As Long
Dim lpSelPath As Long
Dim spath As String * MAX_PATH

With BI
.hOwner = Me.hwnd
.pidlRoot = 0
.lpszTitle = "Select Folder..."
.lpfn = FARPROCl(AddressOf BrowseCallbackProcStr)

lpSelPath = LocalAlloc(LPTR, Len(sSelPath) + 1)
CopyMemory ByVal lpSelPath, ByVal sSelPath, Len(sSelPath) + 1
.lParam = lpSelPath

End With

pidl = SHBrowseForFolder(BI)

If pidl Then

If SHGetPathFromIDList(pidl, spath) Then
BrowseForFolderByPath = Left$(spath, InStr(spath, vbNullChar) - 1)
End If

Call CoTaskMemFree(pidl)

End If

Call LocalFree(lpSelPath)

End Function
 
D

Duane Hookom

You don't tell us which line is generating the code.

I would expect to see some declarations prior to this code like:
'************** Code Start **************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code courtesy of
'Terry Kreft

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long

Private Const BIF_RETURNONLYFSDIRS = &H1
 
B

Brendan Reynolds

Well, a class module that is not a form or report class module would not
have any window associated with it, so it will not have any built-in hwnd
property. You could use Application.hWndAccessApp to get the handle to the
Access application window, or if you plan to call your class method from
code behind a form, you could pass the hwnd property of the form as an
argument to the class method.

In general, the difference between a form class module and just a class
module is that the form class module inherits all the built-in properties,
methods and events of the form.
 
V

Van T. Dinh

You need to place Terry Kreft's code in a *Standard* module, not a Class
module. The CBF (Code-Behind-Form) is a Class module.
 
N

Nikos Yannacopoulos

Chris,

Thi function was intended to reside in a form's module; it has a
reference to the form by means of the Me. keyword (in the first line of
the With block), which is a short way of referring to the form object
but will only work in the form's own module.
In order for it to work in a general module (actually, in any other
module than the form's own one), you need an absolute reference to the
form instead; synatx-wise, that would mean something like:

With BI
.hOwner = Forms("FormName").hwnd

If this is only ever going to be used with one form, the obvious
suggestion is to move the code as is in the form's own module;
alternatively, you could leave the code where it is and just make the
above change, hardcoding the form name - hardcoding is not a very
elegant solution, though.
If, on the contrary, you need to use this with several forms, then leave
the code in the general module, add one more parameter to the function
to pass the form anme and use it in the form reference, like:

Public Function BrowseForFolderByPath(sSelPath As String, sFormName As
String) As String

Dim BI As BROWSEINFO
Dim pidl As Long
Dim lpSelPath As Long
Dim spath As String * MAX_PATH

With BI
.hOwner = Forms(sFormName).hwnd
etc.

Tghen when calling the function form another form, use Me.Name in the
place of the second argument to pass on the form's name.

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

browse for folder code 20
Class module 6
Events trapped in class module 1
Get desktop folder 2
Get File Name 2
List of File Names in a folder 2
Browse for folder - Jim Rech's 4
custom class module 2

Top