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

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Getopenfile In 64 Bit Version, Any Version    
 
   
johnpdmccall
post Jan 18 2020, 11:33 AM
Post#1



Posts: 1,821
Joined: 14-March 00
From: Ayrshire, Scotland


Hi folks

I use the code below on 32 bit versions
What do I need to adjust for 64 bit or do I need something else? If so what?
Thanks for any help

CODE
Function GetOpenFile(Optional varDirectory As Variant, _
    Optional varTitleForDialog As Variant) As Variant
' Here's an example that gets an Access database name.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' Specify that the chosen file must already exist,
' don't change directories when you're done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
    lngFlags = ahtOFN_FILEMUSTEXIST Or _
                ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR
    If IsMissing(varDirectory) Then
        varDirectory = ""
    End If
    If IsMissing(varTitleForDialog) Then
        varTitleForDialog = "Please choose an Image File..."
    End If

    ' Define the filter string and allocate space in the "c"
    ' string Duplicate this line with changes as necessary for
    ' more file templates.
    strFilter = ahtAddFilterItem(strFilter, _
                "Image (*.jpg)", "*.jpg")
    ' Now actually call to get the file name.
    varFileName = ahtCommonFileOpenSave( _
                    openfile:=True, _
                    InitialDir:=varDirectory, _
                    Filter:=strFilter, _
                    Flags:=lngFlags, _
                    DialogTitle:=varTitleForDialog)
    If Not IsNull(varFileName) Then
        varFileName = TrimNull(varFileName)
    End If
    GetOpenFile = varFileName
End Function


This code is part of a module courtesy of:
Microsoft Access 95 How-To
Ken Getz and Paul Litwin
Waite Group Press, 1996

--------------------
Cheers,
John
Go to the top of the page
 
theDBguy
post Jan 18 2020, 12:11 PM
Post#2


UA Moderator
Posts: 77,520
Joined: 19-June 07
From: SunnySandyEggo


Hi John. There's nothing in the code snippet you need to change. What you need to change is the API declarations used by that subroutine to add the PtrSafe keyword and possibly change some Long variables to LongPtr. However, you can avoid all of that if you just use the FileDialog Object instead of the API.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
isladogs
post Jan 18 2020, 12:18 PM
Post#3


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


I had trouble converting similar code to 64-bit and replaced it all with FileDialog which is simpler and works in both 32-bit & 64-bit with no conversion needed
I gave an example of the code used in this post at another forum

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
johnpdmccall
post Jan 18 2020, 01:11 PM
Post#4



Posts: 1,821
Joined: 14-March 00
From: Ayrshire, Scotland


Thanks dbGuy
Thanks Colin but the link to the forum seems to be broken. I can get onto https://www.access-programmers.co.UK/ but can't follow the link in your answer.
It would be great to see an example if anyone has one available as my coding skills are very weak iconfused.gif

PS: I think you've nicked my dog and dyed her black laugh.gif
This post has been edited by johnpdmccall: Jan 18 2020, 01:15 PM

--------------------
Cheers,
John
Go to the top of the page
 
theDBguy
post Jan 18 2020, 01:32 PM
Post#5


UA Moderator
Posts: 77,520
Joined: 19-June 07
From: SunnySandyEggo


Hi John. There's a code example in the link I posted earlier. Are you looking for a file example?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
isladogs
post Jan 18 2020, 01:40 PM
Post#6


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


Hi John
Sorry about the link. The site has been undergoing maintenance for the past few days and is still having issues
Anyway this is the code I posted at that site.
This would be used to browse for Access databases but can easily be modified for other file types or start folders

CODE
Private Sub cmdBrowse_Click()
    
On Error GoTo Err_cmdBrowse_Click

   ' Set options for the dialog box.
    Dim F As FileDialog
    Set F = Application.FileDialog(msoFileDialogFilePicker)
    F.Title = "Locate the Access database file and click on 'Open'"
    F.AllowMultiSelect = False
    
   ' Clear out the current filters, and add our own.
      F.Filters.Clear
      F.Filters.Add "Access Databases", "*.accdb;*.mdb"

   ' Set the start folder (modify as necessary)
    F.InitialFileName = "c:\"
    
' Call the Open dialog routine.
    F.Show

' Return the path and file name.
    strFilename = F.SelectedItems(1)
    
'populate the form control
    Me.txtFile = strFilename

Exit_cmdBrowse_Click:
    Exit Sub

Err_cmdBrowse_Click:
    'err=5, user clicked cancel
    If Err.Number = 5 Then Exit Sub
        
    MsgBox "Error " & err.Number & " in cmdBrowse_Click procedure : " & err.Description
    
    Resume Exit_cmdBrowse_Click
    
End Sub


If you can do so, you might find it worth looking at that whole thread at AWF to which both the DBG & I contributed.

P.S. Isla the dog is slowing going grey now...a bit like me!

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
johnpdmccall
post Jan 18 2020, 01:53 PM
Post#7



Posts: 1,821
Joined: 14-March 00
From: Ayrshire, Scotland


Brilliant thanks guys.
That looks much more simple than what I'm using now. I'll give it a try.
Yes I'll have a look a the thread too

QUOTE
P.S. Isla the dog is slowing going grey now...a bit like me!


Ditto!

--------------------
Cheers,
John
Go to the top of the page
 
johnpdmccall
post Jan 19 2020, 10:56 AM
Post#8



Posts: 1,821
Joined: 14-March 00
From: Ayrshire, Scotland


Thanks again guys you've also inspired me to put together one that finds a folder name - very useful and here's an example. It works fine. Does it look ok?

CODE
Private Sub cmdBuildFolderName_Click()
On Error GoTo Err_cmdBrowse_Click

   ' Set options for the dialog box.
    Dim F As FileDialog
    Set F = Application.FileDialog(msoFileDialogFolderPicker)
    F.Title = "Locate the folder and click 'Open'"
    F.AllowMultiSelect = False
    
   ' Clear out the current filters, and add our own.
      F.Filters.Clear
      
   ' Set the start folder (modify as necessary)
    F.InitialFileName = "c:\"
    
' Call the Open dialog routine.
    F.Show

' Return the path and file name.
    strFolderName = F.SelectedItems(1)
    
'populate the form control
    Me.txtMyFolder = strFolderName
    

Exit_cmdBrowse_Click:
    Exit Sub

Err_cmdBrowse_Click:
    'err=5, user clicked cancel
    If Err.Number = 5 Then Exit Sub
        
    MsgBox "Error " & Err.Number & " in cmdBrowse_Click procedure : " & Err.Description
    
    Resume Exit_cmdBrowse_Click
End Sub

--------------------
Cheers,
John
Go to the top of the page
 
theDBguy
post Jan 19 2020, 11:19 AM
Post#9


UA Moderator
Posts: 77,520
Joined: 19-June 07
From: SunnySandyEggo


Hi John. Glad to hear you got it sorted out. Colin and I were happy to assist. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    24th February 2020 - 03:40 AM