Access 2010 VBA Common Dialogue

So I have this common dialogue code to retrieve a filename that will later be stored in the database.  it was copied directly from Microsoft as a replacement common dialogue since it went away with Office 2007.  Anyway, it has been working wonderfully up until now.  Now whenever it is called, it simply stops running at the 'lReturn = GetOpenFileName(OpenFile)' line.  It opens the dialogue and you can choose your file.  But then it Just stops and no message or anything.  No return to the calling routine.  No anything.  Just stops.

Any ideas as to why this is suddenly happening?  I haven't done any major changes to anything.  Specifically, I have not touched this particular code.

I am calling the LaunchCD function from a subroutine.

Private Sub btnFAPic5_Click()
Dim FN1 As String
Dim FN2 As String

FN1 = LaunchCD(Me)
FN2 = "I:\SDD - Eng\Failure Analysis\Images\"
FN2 = FN2 & Me.SerialNumber.Value
FN2 = FN2 & "_FAPic5"
FN2 = FN2 & GetEXT(FN1)
If Not FN1 = "" Then
    FileCopy FN1, FN2
    FAPicture5 = GetFilnameOnly(FN2)
End If
UpdatePics
End Sub

Open in new window


Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    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

Function LaunchCD(strform As Form) As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim sFilter As String
    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = strform.hWnd
    sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
      "JPEG Files (*.JPG)" & Chr(0) & "*.JPG" & Chr(0)
    OpenFile.lpstrFilter = sFilter
    OpenFile.nFilterIndex = 1
    OpenFile.lpstrFile = String(257, 0)
    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
    OpenFile.lpstrFileTitle = OpenFile.lpstrFile
    OpenFile.nMaxFileTitle = OpenFile.nMaxFile
    OpenFile.lpstrInitialDir = "C:\"
    OpenFile.lpstrTitle = "Select a file using the Common Dialog DLL"
    OpenFile.flags = 0
    lReturn = GetOpenFileName(OpenFile)
        If lReturn = 0 Then
            MsgBox "A file was not selected!", vbInformation, _
              "Select a file using the Common Dialog DLL"
         Else
            LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
         End If
End Function

Open in new window


I would appreciate any advice.  I am stumped.

Thanks,
Elena Quinn
LVL 1
Elena QuinnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Elena QuinnAuthor Commented:
Let me add that I have rebooted my computer several times to no avail.  Though something got messed around with docking and undocking a lot.
0
Elena QuinnAuthor Commented:
So I was messing around more and ran it again only this time I changed directories and chose a file from another directory.  It worked.  So then I went back to the directory I was trying before and chose a file there and it also worked.  But since I had been working in the same directory for a while before this happened, I decided to try it several more times.  After several tries, low and behold it stopped again.  So what does that mean?  It doesn't like to stay in the same directory?  How do I fix it?
0
Jeffrey CoachmanMIS LiasonCommented:
That code, ...still works for me, even in 2013...
I think what happened was that the code will not work with 64 bit versions of MS products.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Jeffrey CoachmanMIS LiasonCommented:
try:
Running the compact repair utility
Also compile the code
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Also be sure your Windows and Office installations are fully up to date.

I also have found that I need to reboot from time to time. I run several different development environments (Access, Excel, Visual Studio. etc) and it seems that after extended periods of time with no reboot I run into quite a few "ghost" issues that I cannot track down (nor recreate). A reboot generally resolves many of those issues (and lets me install updates as well!)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
The "New" dialog box code works fine for me as well. (should work OK for Access 2007 and above)
Here is a sample of the popular, basic code:
https://msdn.microsoft.com/en-us/library/office/ff835934.aspx
...But quickly modified to select one file, and display it in a textbox (Then you can use this value anyway, or anywhere you like)

'Requires reference to Microsoft Office 12.0 Object Library.
 
   Dim fDialog As Office.FileDialog
   Dim varFile As Variant
 
   'Set up the File Dialog.
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
   With fDialog
             
      'Set the title of the dialog box.
      .Title = "Please select a file"
 
      'Clear out the current filters, and add our own.
      .Filters.Clear
      .Filters.Add "Access Databases", "*.MDB; *.ACCDB"
      .Filters.Add "Access Projects", "*.ADP"
      .Filters.Add "All Files", "*.*"
 
      'Show the dialog box. If the .Show method returns True, the
      'user picked a file. If the .Show method returns
      'False, the user clicked Cancel.
      If .Show = True Then
         'Loop through each file selected and add it to the list box.
         For Each varFile In .SelectedItems
            Me.txtFile = varFile
         Next
      Else
         MsgBox "You clicked Cancel in the file dialog box."
      End If
   End With

Open in new window



JeffCoachman
0
Elena QuinnAuthor Commented:
I believe you might be right as I have been doing development in Access, Excel, and PowerPoint over the last few days.  Probably a ghost.

I think in the real world usage, no one is going to use it that way, so hopefully the users won't experience the same issue.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.