Solved

Change filename before saving image

Posted on 2013-11-25
1
248 Views
Last Modified: 2013-12-02
Hello, given the code below how can I change the filename of the image? Perhaps just adding the date to the original filename to help prevent overwriting any images.
Private Sub btn_Add_Picture1_Click()
 Dim strFilter As String
     Dim strInputFileName As String

     strFilter = ahtAddFilterItem(strFilter, "JPEG Files (*.jpg)", "*.jpg")

     strInputFileName = ahtCommonFileOpenSave( _
                             Filter:=strFilter, _
                             OpenFile:=False, _
                             DialogTitle:="Save Image As...", _
                             Flags:=ahtOFN_HIDEREADONLY)
                             
                             
                             Dim strPath As String
strPath = strInputFileName

Dim strFile As String
strFile = Right(strPath, Len(strPath) - InStrRev(strPath, "\"))
                             
     If Len(strInputFileName) > 0 Then
          
     Dim fs As Object
 Dim oldPath As String, newPath As String
 oldPath = strInputFileName
 newPath = GetDefaultFilePath
 Set fs = CreateObject("Scripting.FileSystemObject")
 fs.CopyFile oldPath, newPath & "\" & strFile
 Set fs = Nothing
    Me.txt_Picture1.Visible = True
      Me.txt_Picture1.SetFocus
      Me.txt_Picture1.Text = strFile
      Me!Picture1.Picture = newPath & "\" & strFile
      Screen.PreviousControl.SetFocus
       Me.txt_Picture1.Visible = False
      
     Else
        
     End If
     
End Sub

Open in new window

0
Comment
Question by:gogetsome
1 Comment
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39675665
Dim strFile As String
strFile = Right(strPath, Len(strPath) - InStrRev(strPath, "\"))
strFile=Left(strfile, instr(strFile,".")-1) & "1" & mid(strfile,Instr(strfile,"."))

or you can use date as the number for the file

Dim strFile As String, strDate as string
strDate=Format(Now(),"yyyymmdd")
strFile = Right(strPath, Len(strPath) - InStrRev(strPath, "\"))
strFile=Left(strfile, instr(strFile,".")-1) & "_" & strDate & mid(strfile,Instr(strfile,"."))
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question