UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V  1 2 >  (Go to first unread post)
   Reply to this topicStart new topic
> Get A Filename - Or Fix This Code..., Access 2016    
 
   
Ron38
post Jan 24 2020, 08:47 AM
Post#1



Posts: 245
Joined: 19-August 10
From: New Hampshire


I have spent an hour or 2 looking for a way to get a filename from a user. I copied Ken Getz's code, but it will not compile (see attached). Other suggestions I have seen seem to have obsolete structures in them.
Surely there is a simple access to an API that would get me the user's selected filename?
Many thanks to the crew which always seems to be there to lend a hand!!!
Ron
Attached File(s)
Attached File  Getz_Compile_problem.jpg ( 212.56K )Number of downloads: 13
 
Go to the top of the page
 
orange999
post Jan 24 2020, 09:00 AM
Post#2



Posts: 2,039
Joined: 10-February 08
From: Ottawa, Ont, Canada; West Palm Beach, FL


Ron,

See this M$oft material re FileDialog.

More info if you Google/Bing with ms access filedialog

--------------------
Good luck with your project!
Go to the top of the page
 
jleach
post Jan 24 2020, 09:13 AM
Post#3


UtterAccess Administrator
Posts: 10,434
Joined: 7-December 09
From: St. Augustine, FL


You should be able to remove Global from those Const lines.

Also, as a general convention, I put module level constants above types, but that shouldn't matter syntax-wise.

I'll second the Application.FileDialog suggestion over this though: it's more up to date with advancements in the dialogs since Ken did this code.

--------------------
Jack D. Leach
Founder & CEO
Dymeng Services Inc.
Business Software Solutions
Go to the top of the page
 
BruceM
post Jan 24 2020, 09:19 AM
Post#4


UtterAccess VIP
Posts: 8,025
Joined: 24-May 10
From: Downeast Maine


Is that a form's code module? If so, it may be that moving the code to a standard module will solve the compile error.
Go to the top of the page
 
jleach
post Jan 24 2020, 09:26 AM
Post#5


UtterAccess Administrator
Posts: 10,434
Joined: 7-December 09
From: St. Augustine, FL


>> Form's module <<

Good catch

--------------------
Jack D. Leach
Founder & CEO
Dymeng Services Inc.
Business Software Solutions
Go to the top of the page
 
isladogs
post Jan 24 2020, 10:29 AM
Post#6


UtterAccess VIP
Posts: 2,180
Joined: 4-June 18
From: Somerset, UK


Yet another vote for using FileDialog instead.
The code is much simpler and works in both 32-bit & 64-bit without alteration as it doesn't need an API.

In fact I never managed to get the GetOpenFileName to work in 64-bit even after modifying the API code and it seems I'm not alone in that.

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
Ron38
post Jan 24 2020, 10:44 AM
Post#7



Posts: 245
Joined: 19-August 10
From: New Hampshire


Simpler is better! Would prefer FileDialog, but...
However, I get the attached error when I compile. I do not have 11.0 Object Library, but included 16.0 Object Library, since I am in Access 2016.
I did include the code as part of an On_Click event within a form.
Attached File(s)
Attached File  FileDialog_Problem.jpg ( 98.77K )Number of downloads: 6
 
Go to the top of the page
 
isladogs
post Jan 24 2020, 11:01 AM
Post#8


UtterAccess VIP
Posts: 2,180
Joined: 4-June 18
From: Somerset, UK


Just wondering if you are referring to the default Microsoft Office 16.0 Access database engine object library reference?
Make sure you have the Microsoft Office 16.0 Object Library ticked.

You don't need the Office. in front of FileDialog

Attached File  Capture.PNG ( 36.37K )Number of downloads: 15

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
sxschech
post Jan 24 2020, 12:30 PM
Post#9



Posts: 19
Joined: 2-October 18



If you use late binding, then should not be an issue about setting reference.

CODE
Function selectFile(filetype As String, Optional multifiles As Boolean, Optional sepchar As String = ",")
'--------------------------------------------------
' File Browse Code
'--------------------------------------------------
'Changed from Early to Late Binding
'Does not require reference to Microsoft Office Object Library MSO.DLL
'https://bytes.com/topic/access/answers/942411-late-bind-mso
'https://docs.microsoft.com/en-us/office/vba/api/office.msofiledialogtype
'https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.core.msofiledialogview?view=office-pia
'20181119
'Added semicolon to be sepchar because some files have
'a comma in the file name
'20181210
    Const msoFileDialogFolderPicker = 4
    Const msoFileDialogFilePicker = 3
    Const msoFileDialogViewDetails = 2

    Dim fd As Object
    Dim FileName As String
    Dim i As Variant
    Dim stFilter As String

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
...
...
Go to the top of the page
 
Ron38
post Jan 24 2020, 12:33 PM
Post#10



Posts: 245
Joined: 19-August 10
From: New Hampshire


Yes I checked the Office 16 Object Library.
Removing Office in Office.FileDialog does not correct compile error.
Go to the top of the page
 
Ron38
post Jan 24 2020, 12:55 PM
Post#11



Posts: 245
Joined: 19-August 10
From: New Hampshire


I am not getting anything out of this code: no "Open" window.
Am I missing something?
Go to the top of the page
 
isladogs
post Jan 24 2020, 12:56 PM
Post#12


UtterAccess VIP
Posts: 2,180
Joined: 4-June 18
From: Somerset, UK


Perhaps you have two separate libraries which include the FileDialog reference?
If so, there is a clash not being resolved.
As a test, untick the Microsoft Office 16.0 Object Library then right click FileDialog in that code line & click Definition
See if it finds anything

You can also try late binding as suggested by sxszech

EDIT: Try the simple demo attached which includes FileDialog code


Attached File(s)
Attached File  Browse_AttachFile.zip ( 38.64K )Number of downloads: 3
 

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
Ron38
post Jan 25 2020, 09:14 AM
Post#13



Posts: 245
Joined: 19-August 10
From: New Hampshire


Your db did indeed do what I wanted. I copied the form into my db and get a compile error on dim F as FileDialog - User-defined type not defined.
References contain MS 16.0 Object Library, OLE Automation and VBA. I could not uncheck 16.0 object library: "Can't remove control or reference: In use"
Go to the top of the page
 
isladogs
post Jan 25 2020, 09:37 AM
Post#14


UtterAccess VIP
Posts: 2,180
Joined: 4-June 18
From: Somerset, UK


You're welcome to use my form if it suits your needs.
There is either a reference issue or something has been defined more than once.

Make sure each code module has Option Explicit as the second line then check your code compiles.

Please do a screenshot of your references.
If possible also upload a stripped down copy of your database removing anything confidential.

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
ADezii
post Jan 25 2020, 10:05 AM
Post#15



Posts: 2,755
Joined: 4-February 07
From: USA, Florida, Delray Beach


If you still wish to use Ken Getz's Code, here it is. I made a couple of very minor changes such as: Defaulting to the CurrentProject.Path as the Initial Folder, set a Filter for *.mdb and *.accdb and set the FilterIndex to it, if no File is selected then there will be no Message Box, etc.
Attached File(s)
Attached File  File_Open.zip ( 34.78K )Number of downloads: 6
 
Go to the top of the page
 
Ron38
post Jan 25 2020, 10:59 AM
Post#16



Posts: 245
Joined: 19-August 10
From: New Hampshire


Per your request, attached is a pic of References, and a short test database. It complies with error because I included your form. If that were not there it will compile clean.
Appreciate your attention to this...my wife hates computers, I just have a love-hate relation with them...of course, my wife does not use Access...
Attached File(s)
Attached File  References_screen_shot.jpg ( 150.03K )Number of downloads: 8
 
Go to the top of the page
 
Ron38
post Jan 25 2020, 02:09 PM
Post#17



Posts: 245
Joined: 19-August 10
From: New Hampshire


Thank you. It does indeed work and I have implemented it. I still hope to find out why the simpler FileDialog did not work...
Go to the top of the page
 
isladogs
post Jan 25 2020, 02:19 PM
Post#18


UtterAccess VIP
Posts: 2,180
Joined: 4-June 18
From: Somerset, UK


As I suspected, you need to add the Microsoft Office 16.0 reference library as that includes the FileDialog code
See the highlighted item in my screenshot for post #8 (Mine is 14.0 as I'm using A2010)

BTW you forgot to attach the test database but it shouldn't be needed if you add the missing reference

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
GlenKruger
post Jan 25 2020, 02:58 PM
Post#19


Utterly Crispy UA Forum Administrator
Posts: 8,825
Joined: 29-September 01
From: Edmonton,Alberta,Canada


Good catch Colin!

--------------------
Human nature, it is a funny thing and the hardest thing to program to prevent.
Glen Kruger KNKConsulting
MS Access MVP 2013-2018| Wrox Techincal Contributor
Go to the top of the page
 
Ron38
post Jan 26 2020, 07:44 PM
Post#20



Posts: 245
Joined: 19-August 10
From: New Hampshire


Your post #8 was hard to read and I never expanded it. I also ignored/overlaid mention of Microsoft OFFICE library with Microsoft ACCESS library.
Thank you: Now, keeping the difference in my head...smile.gif
Ron
Go to the top of the page
 
2 Pages V  1 2 >


Custom Search


RSSSearch   Top   Lo-Fi    16th February 2020 - 02:23 PM