Solved

Change filename before saving image

Posted on 2013-11-25
1
242 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 119

Accepted Solution

by:
Rey Obrero 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now