[AccessD] Replacement for comdlg32?

Stuart McLachlan stuart at lexacorp.com.pg
Mon May 8 16:48:07 CDT 2023


I've had the same issue with GetOpenFileName in Access 2021 -  despite using correct API 
declarations :(

GetOpenFileName does nothing, but SHBrowseForFolder still works.

I've actually replaced it with this:

Function GetFileName(Optional Directory As String) As String
If Directory = "" Then Directory = CurrentProject.Path

'Requires reference to Microsoft Office  Object Library.
   Dim fDialog As FileDialog
   Dim varFile As Variant
   'Set up the File Dialog.
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
   With fDialog
      'Allow user to make multiple selections in dialog box.
      .AllowMultiSelect = False
      'Set the title of the dialog box.
      .Title = "Please select the Photo"
      'Clear out the current filters, and add our own.
      .Filters.Clear
      .Filters.Add "All Files", "*.*"
      'Show the dialog box. If the .Show method returns True, the
      'user picked at least one file. If the .Show method returns
      'False, the user clicked Cancel.
      If .Show = True Then
          For Each varFile In .SelectedItems
               GetFileName = varFile
          Next
      End If
   End With
End Function


Your link doesn't say in what version the Application.FIleDialog was introduced. Do you 
know?  (Many of us have clients with some older Office installations)


On 8 May 2023 at 14:47, Jim Dettman via AccessD wrote:

> Rocky,
> 
>   You can use it in 64 bit.   You just need to update the API calls.
>   Those
> can be found here:
> 
> https://jkp-ads.com/articles/apideclarations.asp
> 
> Just do a find on the page for "GetOpenFileName"
> 
> If you don't want to go through that, and are on a later version of
> Access, then you can use the one built in:
> 
> https://learn.microsoft.com/en-us/office/vba/api/access.application.fi
> ledial og
> 
> Jim.
> 
> -----Original Message-----
> From: AccessD On Behalf Of Rocky Smolin
> Sent: Monday, May 8, 2023 2:33 PM
> To: Access Developers discussion and problem solving
> <accessd at databaseadvisors.com>; Off Topic
> <dba-ot at databaseadvisors.com> Subject: [AccessD] Replacement for
> comdlg32?
> 
> I have just discovered that
> 
> Private Declare PtrSafe Function ts_apiGetOpenFileName Lib
> "comdlg32.dll" _
>  Alias "GetOpenFileNameA" (tsFN As tsFileName) As Boolean
> 
> will not run in 64-bit.
> 
> Is there a good replacement?
> 
> MTIA
> 
> Rocky
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 




More information about the AccessD mailing list