Results 1 to 9 of 9
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,185

    Opening File With Unknown Name

    Hi Guy's hope you are all well, i am basing this code to open a file from my camera SD card, when an image is taken, is stores as file name DSC then maybe 6 numbers afterwards, when the SD Card is cleared, another image taken can be another number



    ie: DSC00390, Next image maybe DSC00391 etc....

    I ma trying to open a file that starts in DSC then anything afterwards, the code below just says file not found

    Code:
    Dim camFile as String, SrcPath as String, DriveSelect as String
    DriveSelect = Forms!frmMainMenu!cboDrive 'e:f:g: etc
    SrcPath = DriveSelect & "\DCIM\101MSDCF\"
    CamFile = "DSC" & "*.*" I think it's this line i have got wrong ?
    Application.FollowHyperlink SrcPath & CamFile

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Maybe:
    CamFile = "DSC*"
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,185
    Thanks Bob, ive tried "DSC*" and still can't find the file, the file does exist though!!

    Thanks Dave

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    I would have thought you would need to find the file with the max file number, then use that to open that particular file.?
    What happens if you have DSC00396 as the highest and you want DSC00394 ?

    So either store the filenames in the folder in an array, or just check if the current number is higher that the one stored? If so store that one and get the next file.
    At the end of the loop you will have the file with the highest file number and then you can open it?

    HTH

    Edit: Just found this?
    https://www.roubaixinteractive.com/P...r_Contents.asp
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Shouldn't that be- ...CamFile Like "DSC*"
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    trying to open a file that starts in DSC then anything afterwards
    This is interesting because I'm having trouble imagining that you can invoke Windows to open a file by passing a wildcard as an argument to that operation. The op reads like 'want to open every file whose name starts with DSC'. That could be a lot of files.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Quote Originally Posted by Micron View Post
    This is interesting because I'm having trouble imagining that you can invoke Windows to open a file by passing a wildcard as an argument to that operation. The op reads like 'want to open every file whose name starts with DSC'. That could be a lot of files.
    I agree and thought the same thing. I think there is more to what OP is trying to do than whats been told.

    Maybe some of the code in this example may help.

    This example uses FileSystemObject to get the name of the removeable drives in a listbox (you can uncomment selections in the module to get other type drives.) Selecting a drive shows the directories in that drive (except system folders,etc.) and selecting the directory shows the files in that directory. Selecting the file displays it in an image control. If you want to open the file check the commented code in the double click event and uncomment.

    HTH
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  8. #8
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    You have to use the DIR() function to get the actually file name of the first file in directory.

    Give a try to this:
    Code:
        Dim camFile As String, SrcPath As String, DriveSelect As String
    
        DriveSelect = Forms!frmMainMenu!cboDrive          'e:f:g: etc
        SrcPath = DriveSelect & "\DCIM\101MSDCF\"
        camFile = Dir(SrcPath & "DSC*.*")                 'returns the first matched actually filename 
        
        If Len(camFile) = 0 Then
            MsgBox "There is no any file with name like DSC*.* in directory " & SrcPath, vbExclamation
        Else
            Application.FollowHyperlink SrcPath & camFile
        End If
    Last edited by accesstos; 02-26-2021 at 03:38 PM. Reason: MsgBox message has been updated

  9. #9
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,185
    Thank you guy's i have just managed to get back to this, all working great thank you

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 38
    Last Post: 10-13-2020, 09:30 AM
  2. opening PDF file
    By beaurou in forum Modules
    Replies: 5
    Last Post: 09-09-2014, 01:14 PM
  3. "Unknown" message error while opening a query
    By falahsalih in forum Access
    Replies: 7
    Last Post: 05-23-2014, 04:58 PM
  4. Opening a File
    By Mahendra1000 in forum Access
    Replies: 1
    Last Post: 01-24-2014, 07:45 AM
  5. problem opening .mdb file
    By honeybee in forum Access
    Replies: 7
    Last Post: 06-25-2010, 11:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums