Update fields in a contious form

C

caj

I pieced this together and it is probably kind rough, but if you know an
cleaner way to do it and solve my problem which is: How do I get the fields
[PathFileName] and [DocFileName] to update with the new path and filename? A
button brings the files into the form and another renames, saves them to a
database and moves the files to the archive folder. (2000)

Private Sub SaveDB_Click()

On Error GoTo Err_SaveDB_Click

Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strFolder As String
Dim strNewFolder As String
Dim strNewFile As String
Dim strFileName As String
Dim strOldFile As String
Dim strSQL As String

strFolder = "C:\Vantage\STAGING\"
strNewFolder = "C:\Vantage\SCANS\"

strSQL = "SELECT DType, Numbly, DocFileName FROM STAGE"
Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
If rsCurr.RecordCount = 0 Then
MsgBox "No Record In the Table"
rsCurr.Close
Set rsCurr = Nothing
Set dbCurr = Nothing
Else
With rsCurr
.MoveLast
.MoveFirst

Do While rsCurr.EOF = False

strOldFile = strFolder & rsCurr!DocFileName
strNewFile = strNewFolder & rsCurr!DType & "-" & rsCurr!Numbly & ".pdf"
strFileName = rsCurr!DType & "-" & rsCurr!Numbly & ".pdf"

Me!PathFileName.Value = strNewFile
Me!DocFileName.Value = strFileName
If Len(Dir(strOldFile)) > 0 Then

If Len(Dir(strNewFile)) > 0 Then
If MsgBox(strNewFile & " already exists." & vbCrLf & _
"Overwrite it?", vbYesNo + vbQuestion) = vbYes Then
Kill strNewFile
cancel = True
End If
Else
Name strOldFile As strNewFile


End If
End If

rsCurr.MoveNext

Loop

End With
End If

rsCurr.Close

Set rsCurr = Nothing
Set dbCurr = Nothing

End sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top