We help IT Professionals succeed at work.

User Type not defined

WestBillWest asked
Medium Priority
Last Modified: 2013-11-27
When compiling - Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long  I get an error User Type not defined.  I've gone to references, and tried to open "c:\windows\system32\comdlg32.dll".  I get a message "Can't add a reference to the specified file".   I am using MS Access 2007.  I need the Directory and Folder control.
Watch Question

Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

I use the API at:  http://access.mvps.org/access/api/api0001.htm

In this API, there is a Type statement at the beginning tagOPENFILENAME which defines the type.  Your application should have a similar Type statement.


I not sure of this, but have you check for Filesystemobject, FSO for the function you like to use. FSO is mostly use in VB environment to deal with files and folder.

For your problem, you need to define the type by yourself. No all .dll can be set as reference. Add this to your code and try compile your application once more.

	lStructSize As Long
	hwndOwner As Long
	hInstance As Long
	lpstrFilter As String
	lpstrCustomFilter As String
	nMaxCustomFilter As Long
	nFilterIndex As Long
	lpstrFile As String
	nMaxFile As String
	lpstrFileTitle As String
	nMaxFileTitle As String
	lpstrInitialDir As String
	lpstrTitle As String
	flags As Long
	nFileOffset As Integer
	nFileExtension As Integer
	lpstrDefExt As String
	lCustData As Long
	lpfnHook As Long
	lpTemplateName As String
End Type

Open in new window


I can not use anything that has to do with the comdlg32.dll.  I see it but I can not register it.   I am not an expert and I am having trouble following your solutions.  I need a way for the user to select directories, folders, and files from a control.  Using list boxes is a real pain because of subdirectories/folders.  Could be as simple as I may not know how to view all of the available controls from the menu bar.  I have selected Microsoft Common dialog Control 6.0 (C:\Windows\System32\mscomct2.ocx) in references.  Help...
Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Take a look at the attached sample database.  I put it together the other day for someone to display the Open/Save dialog box (without having to register the comdlg32.dll).  

Type in a path in the path textbox.  Then, if you want to search for a particular string of characters in the filename, type those in the search textbox and click select a file.

The OpenSavedialog will open and after you select a file, the Followhyperlink method will open that file. OpenFile.mdb


Great, worth every dime.  Hopefully someday I can help somebody..

Explore More ContentExplore courses, solutions, and other research materials related to this topic.