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!

Common Dialog does not work in Windows XP 1

Status
Not open for further replies.

fockewulf190

Technical User
Jan 2, 2003
23
US
I created a database on a machine that had Windows 98 using Office 2000. I took this database to a Windows XP machine that has Office 2000 and the Common Dialog box button that I had made does not work. Can anyone tell me why and how to correct this problem? Will this happen if I install the database on a Windows 2000 or Windows NT machine?


Thanks
Charles
 
Hi fockewulf190,

I think I'm right in saying this.

The Common Dialog Control is usually distributed with Access Runtime or Visual Studio/Basic. If the PC you are installing your app on doesn't have either of these the CDC won't work.

If you have Access Runtime, using the Packaging and Deployment Wizard you can make your App installable with a Setup.exe program, then when you install your App using Setup on any other PC the CDC will be installed and made available at the same time.

Otherwise, you can create your own which will be available on any PC it is installed on. If you look at CommonDialogAccess2000.zip will show how this is done using Windows API's. The demo shows how to retrieve the selected:

1. Folder name
2. File name
3. Folder and File name.

If you need any further help on this, please let me know.

Bill
 
Bill,

Let me first thank you for responding to my post with a very indepth and informative coverage of the Common Dialog. I will show you the code I am using. This code is begun when a command button is clicked and opens a dialog box allowing the user to select the path to an outside database (An office 97 database) and the selection is the source of imported data.

Type tagOPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
strFilter As String
strCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
strFile As String
nMaxFile As Long
strFileTitle As String
nMaxFileTitle As Long
strInitialDir As String
strTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
strDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean

Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean

Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long

Global Const ahtOFN_READONLY = &H1
Global Const ahtOFN_OVERWRITEPROMPT = &H2
Global Const ahtOFN_HIDEREADONLY = &H4
Global Const ahtOFN_NOCHANGEDIR = &H8
Global Const ahtOFN_SHOWHELP = &H10
' You won't use these.
'Global Const ahtOFN_ENABLEHOOK = &H20
'Global Const ahtOFN_ENABLETEMPLATE = &H40
'Global Const ahtOFN_ENABLETEMPLATEHANDLE = &H80
Global Const ahtOFN_NOVALIDATE = &H100
Global Const ahtOFN_ALLOWMULTISELECT = &H200
Global Const ahtOFN_EXTENSIONDIFFERENT = &H400
Global Const ahtOFN_PATHMUSTEXIST = &H800
Global Const ahtOFN_FILEMUSTEXIST = &H1000
Global Const ahtOFN_CREATEPROMPT = &H2000
Global Const ahtOFN_SHAREAWARE = &H4000
Global Const ahtOFN_NOREADONLYRETURN = &H8000
Global Const ahtOFN_NOTESTFILECREATE = &H10000
Global Const ahtOFN_NONETWORKBUTTON = &H20000
Global Const ahtOFN_NOLONGNAMES = &H40000
Global Const ahtOFN_EXPLORER = &H80000
Global Const ahtOFN_NODEREFERENCELINKS = &H100000
Global Const ahtOFN_LONGNAMES = &H200000

Function ahtCommonFileOpenSave( _
Optional ByRef Flags As Variant, _
Optional ByVal InitialDir As Variant, _
Optional ByVal filter As Variant, _
Optional ByVal FilterIndex As Variant, _
Optional ByVal DefaultExt As Variant, _
Optional ByVal FileName As Variant, _
Optional ByVal DialogTitle As Variant, _
Optional ByVal Hwnd As Variant, _
Optional ByVal OpenFile As Variant) As Variant

' This is the entry point you'll use to call the common
' file open/save dialog. The parameters are listed
' below, and all are optional.
'
' In:
' Flags: one or more of the ahtOFN_* constants, OR'd together.
' InitialDir: the directory in which to first look
' Filter: a set of file filters, set up by calling
' AddFilterItem.
' FilterIndex: 1-based integer indicating which filter
' set to use, by default (1 if unspecified)
' DefaultExt: Extension to use if the user doesn't enter one.
' Only useful on file saves.
' FileName: Default value for the file name text box.
' DialogTitle: Title for the dialog.
' hWnd: parent window handle
' OpenFile: Boolean(True=Open File/False=Save As)
' Out:
' Return Value: Either Null or the selected filename
Dim OFN As tagOPENFILENAME
Dim strFilename As String
Dim strFileTitle As String
Dim fResult As Boolean
' Give the dialog a caption title.
If IsMissing(InitialDir) Then InitialDir = CurDir
If IsMissing(filter) Then filter = ""
If IsMissing(FilterIndex) Then FilterIndex = 1
If IsMissing(Flags) Then Flags = 0&
If IsMissing(DefaultExt) Then DefaultExt = ""
If IsMissing(FileName) Then FileName = ""
If IsMissing(DialogTitle) Then DialogTitle = ""
If IsMissing(Hwnd) Then Hwnd = Application.hWndAccessApp
If IsMissing(OpenFile) Then OpenFile = True
' Allocate string space for the returned strings.
strFilename = Left(FileName & String(256, 0), 256)
strFileTitle = String(256, 0)
' Set up the data structure before you call the function
With OFN
.lStructSize = Len(OFN)
.hwndOwner = Hwnd
.strFilter = filter
.nFilterIndex = FilterIndex
.strFile = strFilename
.nMaxFile = Len(strFilename)
.strFileTitle = strFileTitle
.nMaxFileTitle = Len(strFileTitle)
.strTitle = DialogTitle
.Flags = Flags
.strDefExt = DefaultExt
.strInitialDir = InitialDir
' Didn't think most people would want to deal with
' these options.
.hInstance = 0
.strCustomFilter = ""
.nMaxCustFilter = 0
.lpfnHook = 0
'New for NT 4.0
.strCustomFilter = String(255, 0)
.nMaxCustFilter = 255
End With


' This will pass the desired data structure to the
' Windows API, which will in turn it uses to display
' the Open/Save As Dialog.
If OpenFile Then
fResult = aht_apiGetOpenFileName(OFN)
Else
fResult = aht_apiGetSaveFileName(OFN)
End If

' The function call filled in the strFileTitle member
' of the structure. You'll have to write special code
' to retrieve that if you're interested.
If fResult Then
' You might care to check the Flags member of the
' structure to get information about the chosen file.
' In this example, if you bothered to pass in a
' value for Flags, we'll fill it in with the outgoing
' Flags value.
If Not IsMissing(Flags) Then Flags = OFN.Flags
ahtCommonFileOpenSave = TrimNull(OFN.strFile)
Else
ahtCommonFileOpenSave = "NoFile"
End If
End Function

Function ahtAddFilterItem(strFilter As String, _
strDescription As String, Optional varItem As Variant) As String
' Tack a new chunk onto the file filter.
' That is, take the old value, stick onto it the description,
' (like "Databases"), a null character, the skeleton
' (like "*.mdb;*.mda") and a final null character.

If IsMissing(varItem) Then varItem = "*.*"
ahtAddFilterItem = strFilter & _
strDescription & vbNullChar & _
varItem & vbNullChar
End Function


Private Function TrimNull(ByVal strItem As String) As String
Dim intPos As Integer
intPos = InStr(strItem, vbNullChar)
If intPos > 0 Then
TrimNull = Left(strItem, intPos - 1)
Else
TrimNull = strItem
End If
End Function


Should this work on a machine with Windows 2000,NT,or XP that has Access 2000 on it?
 
Hi again,

I've just tested your code on my PC, Windows XP, works perfectly. I'm at a loss as to why your experiencing this problem.

The only thing I can suggest is that you try the download I suggested earlier. My API calls and Constants are different
to yours. Also, maybe you could try using your app on another PC, if the CDC works then at least you know it's local to the PC above if not, I don't know what to suggest.

Let me know how you get on. Thanks for the star, but it's undeserved as I haven't solved your problem.

Bill
 
Bill thanks again for your help.... you did help me out partially that's what the star was for. I was wondering if I might be having reference problems. What are the references that the database should be showing?



Thanks

Charles
 
I can say for sure that it is not a References problem.

Should have asked this before, but when you say "it doesn't work".

1. Does the CDC open up at all or is it just not returning anything when a File is selected.

2. Are you getting any Error Message when trying to open the CDC.

3. While in the Visual Basic Editor, from the Menu select Debug->> Compile, do you get an Error Message after selecting Compile.

4. What is the code you are using to try to open the CDC. i.e. to get a Message Box returning the selected File the Code would be: MsgBox ahtCommonFileOpenSave

Bill
 
Bill,

I managed to get the database to work. The problem was indeed the References. The common dialog was not referenced and so I had to get the comdlg32.ocx file and install it. I do not use the designer version of Access so I imagine the libraries are not being taken along with the database when it is moved to a new machine (correct me if I'm wrong) I appreciate your help... Thanks again

Oh here were the symptoms of the problem:

-When button was clicked the Common Dialog procedure did not execute. Nothing happened at all.

-There were no error messages.

Upon checking the references on the machine the database was installed on it was found that the reference to Common Dialog was not there.

Thanks
 
Hi fockewulf190,

I am delighted that you finally got your CDC to work.

But, I have to stand by original statement "I can say for sure that it is not a References problem."

Your API driven CDC (code above) and the CDC I suggested you take a look at on my "site" do not require the ActiveX Control comdlg32.ocx to be Installed and definitely not Registered on the Host PC. That's the whole idea of using API's, comdlg32.ocx is not readily available for use unless the App is installed by Access Runtime or Access Runtime, Visual Studio or similar is installed on the User's PC.

Maybe there is someone out there that can solve this mystery. I've just gone to the extreme measure of (temporarily) Deleting comdlg32.ocx from my Windows/System Directory, both your's and my Version of the API CDC still work perfectly.

Anyway, thanks for letting me know that you got it working.

Good Luck

Bill

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top