Copying/Renaming files based on data in a table

S

sbradley0

Basically, I'm trying to do what it says in the subject. I have a
table (tblReportsMe) with three fields:

woindex (unique)
wofile (current path to a specific file, eg. c:\00916678423 ... file
has no extention)
worepname (desired name of the file)

I'm trying to copy the files and rename them from a form, using a the
following sub:

Private Sub btnRenameFiles_Click()

Dim rstAny As DAO.Recordset
Dim dbAny As DAO.Database
Dim strFrom As String
Dim strTo As String

Set dbAny = CurrentDb()
Set rstAny = dbAny.OpenRecordset("SELECT DISTINCT woindex, worepname,
wofile FROM tblReportsMe")

While Not rstAny.EOF
strFrom = wofile
strTo = "C:\Documents and Settings\All Users\Documents\CFx\Month End
Reports\" & worepname & ".txt"
FileCopy strFrom, strTo
 
S

sbradley0

Sorry, tabbed accidentally, full code:

Private Sub btnRenameFiles_Click()

Dim rstAny As DAO.Recordset
Dim dbAny As DAO.Database
Dim strFrom As String
Dim strTo As String

 Set dbAny = CurrentDb()
 Set rstAny = dbAny.OpenRecordset("SELECT DISTINCT woindex, worepname,
wofile FROM tblReportsMe")

 While Not rstAny.EOF
  strFrom = wofile
  strTo = "C:\Documents and Settings\All Users\Documents\CFx\Month End
Reports\" & worepname & ".txt"
FileCopy strFrom, strTo
rstAny.MoveNext
Wend

End Sub

The problem is that it keeps saying that wofile and worepname are
"empty". Any help?

Thanks!
 
S

Stuart McCall

Sorry, tabbed accidentally, full code:

Private Sub btnRenameFiles_Click()

Dim rstAny As DAO.Recordset
Dim dbAny As DAO.Database
Dim strFrom As String
Dim strTo As String

Set dbAny = CurrentDb()
Set rstAny = dbAny.OpenRecordset("SELECT DISTINCT woindex, worepname,
wofile FROM tblReportsMe")

While Not rstAny.EOF
strFrom = wofile
strTo = "C:\Documents and Settings\All Users\Documents\CFx\Month End
Reports\" & worepname & ".txt"
FileCopy strFrom, strTo
rstAny.MoveNext
Wend

End Sub

The problem is that it keeps saying that wofile and worepname are
"empty". Any help?

Thanks!

You forgot to prefix them with the recordset variable. They should look
like:

strFrom = rstAny!wofile

and:

& rstAny!worepname &
 
S

sbradley0

Sorry, tabbed accidentally, full code:

Private Sub btnRenameFiles_Click()

Dim rstAny As DAO.Recordset
Dim dbAny As DAO.Database
Dim strFrom As String
Dim strTo As String

Set dbAny = CurrentDb()
Set rstAny = dbAny.OpenRecordset("SELECT DISTINCT woindex, worepname,
wofile FROM tblReportsMe")

While Not rstAny.EOF
strFrom = wofile
strTo = "C:\Documents and Settings\All Users\Documents\CFx\Month End
Reports\" & worepname & ".txt"
  FileCopy strFrom, strTo
  rstAny.MoveNext
 Wend

End Sub

The problem is that it keeps saying that wofile and worepname are
"empty".  Any help?

Thanks!

You forgot to prefix them with the recordset variable. They should look
like:

strFrom = rstAny!wofile

and:

& rstAny!worepname &

Great, thanks!
 

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