Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CONTROL COULD NOT BE CREATED ERROR

Status
Not open for further replies.

vbcad

Technical User
Jul 12, 2002
159
US
i AM TRYING TO ADD A OPEN DIALOG BOX USING THE MICROSOFT COMMON DIALOG CONTROL VERSION 6.0 IN VBA WITH ACAD 2004. I GET THE "CONTROL COULD NOT BE CREATED BECAUSE IT IS NOT PROPERLY LICENSED" I HAVE TRIED REINSTALLING OFFICE TO SEE IF THIS WOULD WORK I HAVE RECENTLY APPLIED SERVICE PACK 2 TO WINDOWS XP. I HAVE EVEN TRIED CLEANING OUT THE REGISTRY AND RE REGISTERING THE CONTROL. NOTHING WORKS. ANY IDEAS?
 
vbcad,

What version of Office are you using? This was a known problem with Office 97 - the fix was SR-1 so if you don't have the latest service pack for Office - try installing that (even if you're on a more recent version of Office).

Also, if you haven't already, try installing the latest service packs for AutoCAD, there should be a service pack 2 for 2004.

HTH
Todd
 
i have office xp. as far as the cad pack i will try that. i have looked on several forums and noone seem to have a fix for this error. all i can find is reinstall the activex control. finding help for this is next to impossible
 
vbcad,

Not sure if you're aware of this or not, but the common control is not licensed for use with VBA unless you have either Visual Basic/Visual Studio or Office developer installed. There are several replacements for the common control if you don't have one of those installed.

Try:
Code:
Option Explicit
Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2

Public Const OFN_ALLOWMULTISELECT As Long = &H200
Public Const OFN_CREATEPROMPT As Long = &H2000
Public Const OFN_ENABLEHOOK As Long = &H20
Public Const OFN_ENABLETEMPLATE As Long = &H40
Public Const OFN_ENABLETEMPLATEHANDLE As Long = &H80
Public Const OFN_EXPLORER As Long = &H80000
Public Const OFN_EXTENSIONDIFFERENT As Long = &H400
Public Const OFN_FILEMUSTEXIST As Long = &H1000
Public Const OFN_HIDEREADONLY As Long = &H4
Public Const OFN_LONGNAMES As Long = &H200000
Public Const OFN_NOCHANGEDIR As Long = &H8
Public Const OFN_NODEREFERENCELINKS As Long = &H100000
Public Const OFN_NOLONGNAMES As Long = &H40000
Public Const OFN_NONETWORKBUTTON As Long = &H20000
Public Const OFN_NOREADONLYRETURN As Long = &H8000& 'see comments
Public Const OFN_NOTESTFILECREATE As Long = &H10000
Public Const OFN_NOVALIDATE As Long = &H100
Public Const OFN_OVERWRITEPROMPT As Long = &H2
Public Const OFN_PATHMUSTEXIST As Long = &H800
Public Const OFN_READONLY As Long = &H1
Public Const OFN_SHAREAWARE As Long = &H4000
Public Const OFN_SHAREFALLTHROUGH As Long = 2
Public Const OFN_SHAREWARN As Long = 0
Public Const OFN_SHARENOWARN As Long = 1
Public Const OFN_SHOWHELP As Long = &H10
Public Const OFS_MAXPATHNAME As Long = 260

'OFS_FILE_OPEN_FLAGS and OFS_FILE_SAVE_FLAGS below
'are mine to save long statements; they're not
'a standard Win32 type.
Public Const OFS_FILE_OPEN_FLAGS = OFN_EXPLORER _
Or OFN_LONGNAMES _
Or OFN_CREATEPROMPT _
Or OFN_NODEREFERENCELINKS

Public Const OFS_FILE_SAVE_FLAGS = OFN_EXPLORER _
Or OFN_LONGNAMES _
Or OFN_OVERWRITEPROMPT _
Or OFN_HIDEREADONLY

Public Type OPENFILENAME
nStructSize As Long
hWndOwner As Long
hInstance As Long
sFilter As String
sCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
sFile As String
nMaxFile As Long
sFileTitle As String
nMaxTitle As Long
sInitialDir As String
sDialogTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
sDefFileExt As String
nCustData As Long
fnHook As Long
sTemplateName As String
pvReserved As Long
dwReserved As Long
FlagsEx As Long
End Type

Public OFN As OPENFILENAME

'windows-defined type OSVERSIONINFO
Public Type OSVERSIONINFO
OSVSize As Long 'size, in bytes, of this data structure
dwVerMajor As Long 'ie NT 3.51, dwVerMajor = 3; NT 4.0,
dwVerMajor = 4.
dwVerMinor As Long 'ie NT 3.51, dwVerMinor = 51; NT 4.0,
dwVerMinor= 0.
dwBuildNumber As Long 'NT: build number of the OS
'Win9x: build number of the OS in
low-order word.
'High-order word contains major & minor
ver nos.
PlatformID As Long 'Identifies the operating system
platform.
szCSDVersion As String * 128 'NT: string, such as "Service Pack 3"
'Win9x: 'arbitrary additional
information'
End Type

Public Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long

Public Declare Function GetOpenFileName Lib "comdlg32" _
Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long

Public Declare Function GetSaveFileName Lib "comdlg32" _
Alias "GetSaveFileNameA" _
(pOpenfilename As OPENFILENAME) As Long

Public Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal cchBuffer As Long) As Long

Public Function BrowseFor(sDesc As String, sExt As String, _
Optional lHwnd As Long, Optional sTitle As
String) _
As String
'used in call setup
Dim sFilters As String
'create a string of filters for the dialog
sFilters = sDesc & vbNullChar & sExt & vbNullChar & vbNullChar

With OFN
'size of the OFN structure
.nStructSize = IIf(IsWin2000Plus(), Len(OFN), Len(OFN) - 12)
If lHwnd Then
'window owning the dialog
.hWndOwner = lHwnd
End If
'filters (patterns) for the dropdown combo
.sFilter = sFilters
'index to the initial filter
.nFilterIndex = 2
'default filename, plus additional padding
'for the user's final selection(s). Must be
'double-null terminated
.sFile = sExt & Space$(1024) & vbNullChar & vbNullChar
'the size of the buffer
.nMaxFile = Len(.sFile)
'default extension applied to
'file if it has no extention
.sDefFileExt = sExt & vbNullChar & vbNullChar
'space for the file title if a single selection
'made, double-null terminated, and its size
.sFileTitle = vbNullChar & Space$(512) & vbNullChar & vbNullChar
.nMaxTitle = Len(OFN.sFileTitle)
'starting folder, double-null terminated
.sInitialDir = "c:\" & vbNullChar & vbNullChar
'the dialog title
.sDialogTitle = IIf(sTitle <> "", sTitle, "BrowseFor")
'default open flags and multiselect
.flags = OFS_FILE_OPEN_FLAGS Or _
OFN_ALLOWMULTISELECT
End With
'call the API
If GetOpenFileName(OFN) Then BrowseFor = OFN.sFile

End Function
Public Function IsWin2000Plus() As Boolean
'returns True if running Windows 2000 or better
Dim OSV As OSVERSIONINFO
OSV.OSVSize = Len(OSV)
If GetVersionEx(OSV) = 1 Then
IsWin2000Plus = (OSV.PlatformID = VER_PLATFORM_WIN32_NT) And _
(OSV.dwVerMajor = 5 And OSV.dwVerMinor >= 0)
End If
End Function

'Make a button called cmdBrowse to test:
Sub cmdBrowse_Click()
Dim sFile As String
'get the file
sFile = Trim(BrowseFor("ASCII Text file", "*.txt", _
Me.hwnd, "Select File List"))
End Sub

'In the above, you need to add the ability to grab a form's handle
'if you are using vba. Paste this code into the UserForm:
Private Declare Function GetActiveWindow Lib "user32" () As Long

Public Property Get hwnd() As Long
hwnd = GetActiveWindow()
End Property

or try downloading this:

There is an article on the MSDN that may also help:

HTH
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top