CommonDialog Broken?

M

Mike

We have some code that uses the CommonDialog ocx and has worked fine for
months however it has now stopped working on some of our PC's. On the PC's
that it fails, they have version 6.1.97.82 of comdlg32.ocx and the PC's that
work have version 6.0.88.77. Is the new version of CommonDialog no longer
compatible with MSAccess 2002?

Steps to recreate the problem.

In MSAccess 2002
1 - Create a form
2 - Add the CommonDialog control and name it cdl
3 - Add a command button and name it command1
4 - Add the code below to the form
5 - Save the form and open it
6 - Click the command button to launch the FileDialog
7 - Click Cancel on the FileDialog
8 - Click the command button again and you will get a Type Mismatch error



Private Sub Command1_Click()

Dim o As CommonDialog

On Error GoTo Err_Command1_Click

Set o = Me!cdl.Object

With o
.CancelError = True
.ShowOpen
End With

MsgBox o.FileName

Exit_Command1_Click:

Set o = Nothing

Exit Sub

Err_Command1_Click:

MsgBox Err.Number & ": " & Err.Description
Resume Exit_Command1_Click

End Sub
 
K

Karl E. Peterson

Mike said:
We have some code that uses the CommonDialog ocx and has worked fine
for months however it has now stopped working on some of our PC's.

Can't tell you how many times I've heard similar frustrations with that OCX, and I
share them. It's a needless pain, when the API is so conveniently available. Who
needs the extra dependency?

I haven't built it up as a standalone sample, but I think you'd like to take a look
at the CFileDlg class module in:

http://vb.mvps.org/samples/MapFile

It can be dropped right into any VBA application, and used directly, as shown in the
VB Form used in this sample:

Private Sub cmdBrowse_Click()
Dim dlg As New CFileDialog
Dim file As String
Dim flags As Long

' Ask user for filename.
If dlg.GetOpenFileName(file, , , , , True, , , , "Choose File to Encrypt", ,
Me.hWnd, flags) Then
txtFile.Text = file
End If
End Sub

Enjoy... Karl
 

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

Top