How to save a file using a variable?

PuddinPie

Registered User.
Local time
, 20:41
Joined
Sep 15, 2010
Messages
149
In Access 97, what I would like happen is that a user clicks on a button in a form and it opens a file explorer window (Like a save as or open file window). When they select there file the computer moves the file to a different folder and renames it based on a veriable in a form.
Is that possiable?

Thank you.
 
I took a look and could not really find what I was looking for. Essentualy I want to import a file from one dir to another and rename the file when it get's there.
 
Here is the code behind the 'Add Attachment' button:-

Code:
Private Sub Command231_Click()
'Add attachments to Change Request
On Error GoTo ErrorHandler
    Dim strFilter As String
    Dim strInputFileName As String
    Dim strSQL As String
'Check to see if any more attachments can be added
        If Len(Nz(Me.Attachment1, "")) <> 0 Then
            If Len(Nz(Me.Attachment2, "")) <> 0 Then
                If Len(Nz(Me.Attachment3, "")) <> 0 Then
                    MsgBox "You cannot add any more attachments"
                    Exit Sub
                End If
            End If
        End If
'Add attachment to first available field
'Take copy of file to be attached and
'place copy in directory on K:\ drive
'Place hyperlink to file on K:\ drive
'in appropriate attachment field
    strFilter = ahtAddFilterItem(strFilter, _
    "All Files (*.*)", _
    "*.*")
    strInputFileName = ahtCommonFileOpenSave(Filter:=strFilter, _
    OpenFile:=True, _
    DialogTitle:="Please select an input file...", _
    Flags:=ahtOFN_HIDEREADONLY)
    
        If Len(Nz(Me.Attachment1, "")) = 0 Then
            Me.Attachment1 = strInputFileName
            Dim origpath, newpath As String
            Me.Attachment1.SetFocus
            origpath = Me.Attachment1.Text
            newpath = "K:\Rapid\BST - general\Release Testing\Change Request Log\Attachments\" & "CR" & (Me.Abbreviation) & Format(Me.RequestID, "00000") & "Att1" & Right(Me.Attachment1, 4)
            FileCopy origpath, newpath
            Me.Attachment1 = newpath
        ElseIf Len(Nz(Me.Attachment2, "")) = 0 Then
            Me.Attachment2 = strInputFileName
            Me.Attachment2.SetFocus
            origpath = Me.Attachment2.Text
            newpath = "K:\Rapid\BST - general\Release Testing\Change Request Log\Attachments\" & "CR" & (Me.Abbreviation) & Format(Me.RequestID, "00000") & "Att2" & Right(Me.Attachment2, 4)
            FileCopy origpath, newpath
            Me.Attachment2 = newpath
        ElseIf Len(Nz(Me.Attachment3, "")) = 0 Then
            Me.Attachment3 = strInputFileName
            Me.Attachment3.SetFocus
            origpath = Me.Attachment3.Text
            newpath = "K:\Rapid\BST - general\Release Testing\Change Request Log\Attachments\" & "CR" & (Me.Abbreviation) & Format(Me.RequestID, "00000") & "Att3" & Right(Me.Attachment3, 4)
            FileCopy origpath, newpath
            Me.Attachment3 = newpath
        End If
'Message to user if they cancel the operation
ErrorHandler:
    If Err = 75 Then
        MsgBox "You have not selected a file to attach to this Change Request"
    ElseIf Err = 76 Then
        MsgBox "You have not selected a file to attach to this Change Request"
    End If
    
End Sub

Have a look at it and edit it to suit your needs
 

Users who are viewing this thread

Back
Top Bottom