Results 1 to 12 of 12
  1. #1
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,193

    How To Use Asterix In Partial File Name

    Hi Guy's i'm lost again, how do i use the asterix in a partial file Name again ??

    Trying find if a file called : table_ and *.* .xlsx exists in Downloads folder

    If it does then rename to another folder

    I am getting bad file name, when hover over strdwnFile, this is blank as it can't find file name: table_ then "*"

    Code:
    Dim strdwnFile As String, strdwnPath As String, strNewFile As String, strNewPath As String
    
    strdwnPath = Environ("USERPROFILE") & "\Downloads\"
    strNewPath = "T:\DMT Ltd\Fuel Price Sheets\"
    
    
    strNewFile = "Fuel Prices " & Format(Now(), "dd-mmm-yyyy") & ".xlsx"
    
    
    strdwnFile = Dir(strdwnPath & "table_*.xlsx")
    
    
    
    
        If Len(Dir(strdwnPath & strdwnFile)) > 0 Then
            Name strdwnPath & strdwnFile As strNewPath & strNewFile
            Kill strdwnPath & strdwnFile
        End If
        
        If Len(Dir(strdwnPath & strdwnFile)) = 0 Then
            MsgBox ("Your File Doesn't Exist In Downloads, It Requires Downloading"), vbInformation + vbOKOnly, "NO FILE IN DOWNLOADS"
        End If
    
    
        Application.FollowHyperlink strNewPath
    Again, thank you guy's for your help

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I'm sure we've been down this route before, I don't think you can rely on a wild card in a DIR command?
    Try experimenting with it in the immediate window?

    I think it always returns the first file it finds from memory?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    @Dave - what do you get with this modified code:
    Code:
    Dim strdwnFile As String, strdwnPath As String, strNewFile As String, strNewPath As String
    
    
    strdwnPath = Environ("USERPROFILE") & "\Downloads\"
    strNewPath = "T:\DMT Ltd\Fuel Price Sheets\"
    strNewFile = "Fuel Prices " & Format(Now(), "dd-mmm-yyyy") & ".xlsx
    
    
    strdwnFile = Dir(strdwnPath & "table_*.xlsx")
    
    
    If strdwnFile <> "" Then
       Name strdwnPath & strdwnFile As strNewPath & strNewFile
       Kill strdwnPath & strdwnFile
    Else
    	MsgBox ("Your File Doesn't Exist In Downloads, It Requires Downloading"), vbInformation + vbOKOnly, "NO FILE IN DOWNLOADS"
    End If
        
    Application.FollowHyperlink strNewPath
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,193
    Bingo Vlad, thank you and Minty, added a check if file already saved, the only other thing I am not understanding after testing a few times, i have commented out the Kill statement, but the file in downloads still deletes ?

    It works though but if i bypass kill, is there something i am missing here ?

    Code:
    Private Sub cmdDownload_Click()
    
        
    Dim strdwnFile As String, strdwnPath As String, strNewFile As String, strNewPath As String
    
    
    
    
    strdwnPath = Environ("USERPROFILE") & "\Downloads\"
    strNewPath = "T:\DMT Ltd\Fuel Price Sheets\"
    strNewFile = "Fuel Prices " & Format(Now(), "dd-mmm-yyyy") & ".xlsx"
    
    
    
    
    strdwnFile = Dir(strdwnPath & "table_*.xlsx")
    
    
    If Len(Dir(strNewPath & strNewFile)) > 0 Then
        
        MsgBox ("You Already Have A File Called: " & vbNewLine & vbNewLine & _
            "In: " & strNewPath & vbNewLine & vbNewLine & _
            "Called: " & strNewFile), vbInformation + vbOKOnly, "FILE EXISTS"
                                    
            Exit Sub
            
    End If
    
    
    If Len(Dir(strNewPath & strNewFile)) = 0 Then
    
    
        If strdwnFile <> "" Then
            Name strdwnPath & strdwnFile As strNewPath & strNewFile
            'Kill strdwnPath & strdwnFile
        
        Else
            
            MsgBox ("Your File Doesn't Exist In Downloads, It Requires Downloading"), vbInformation + vbOKOnly, "NO FILE IN DOWNLOADS"
        
        End If
        
    End If
    
    
    Application.FollowHyperlink strNewPath
    
    
    Debug.Print strdwnFile
    
    
    
    
    End Sub
    Click image for larger version. 

Name:	Capture.JPG 
Views:	14 
Size:	95.3 KB 
ID:	49166

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    If you care to know, it's an asterisk. If not, just ignore me.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    @Dave - the Name command renames (or moves the file) so there isn't anything left to kill......
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,193
    Vlad, thank you, if there was an enemy in this crazy world it's Dave vs Dave

    I forget where i use similar code in the past to look back on, copy it, re dim / rename to suit new procedures

    Frustratingly I have a table called tblCode with fields, this has fields called: ID, Subject, Code (set as long Text), Notes

    I am meant to add a Subject, Paste Code that works into Code Field and a brief explanation to what the code does

    Do I use it ? NO not like I should, i guess in the haste of crazy day's, is the reason

    WGM mentioned a while ago to go on a time management course, i think it's a fair comment

    I just need to find a brain reset course too

    truly, thank you for helping and being patient

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    WGM mentioned a while ago to go on a time management course, i think it's a fair comment
    I do not remember that?, or see where it could help you?
    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

  9. #9
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,193
    Yes you mentioned you once went on a time management course, please forgive me if i am wrong, sure you did though

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Seemed familiar to me. Not too hard to find but I'm not sure what the meaning behind the post was

    https://www.accessforums.net/showthr...682#post484682
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,193
    @micron, yes that was the one, I'm always dragged from pillar to post, this stops concentration and completing tasks!!

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Ok, I see where that was used in the fact you were complaining you were getting pulled away from your work.
    However my point there was whilst you might manage your time effectively, that was just you not your team members who might need help. So I would always stop to help, and get told off for doing so.

    In fact when I worked at Lloyds bank, a colleague was asked why they took so long on a case. The reason was they were helping one of the permanent staff, and there was no provision to allocate time against anything other than the cases you were assigned.
    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

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

Similar Threads

  1. Partial numbers in the entries
    By mercer in forum Access
    Replies: 1
    Last Post: 08-12-2016, 10:42 AM
  2. Delete Partial String HELP!!
    By Crawfordrider33 in forum Access
    Replies: 2
    Last Post: 05-15-2015, 11:31 AM
  3. Import Partial Excel File into Database
    By AndrogynyRocks in forum Access
    Replies: 3
    Last Post: 04-13-2012, 02:31 PM
  4. partial display
    By tawright in forum Access
    Replies: 2
    Last Post: 07-20-2011, 09:38 AM
  5. Partial Limit
    By bglaugh in forum Programming
    Replies: 1
    Last Post: 09-15-2010, 06:49 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