Use access to rename image files

G

Guest

I have an Access database which has records of products. There is a product
ID field and a field which gives the name of the associated product image. I
need to rename the image to match the product ID exactly. I'm sure there is
a way to automate this task, but my mind isn't in the right place. Can
anyone help?

Product ID Image ID
247654 dogbed.jpg

Image ID must become: 247654.jpg
 
D

Douglas J. Steele

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

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\SomeFolder\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT ProductID, ImageID FROM MyTable"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr!ProductID & ".jpg"
strOldFile = strFolder & rsCurr!ImageID
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0 Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

rsCurr.Close
Set rsCurr = Nothing
Set dbCurr = Nothing
 
G

Guest

Hey Douglas,

Thanks for the code. I'm getting a syntax error on the -Set rsCurr =
dbCurr.OpenRecordset(strSQL)-line. I looked at the VB help example, but
couldn't figure out what I should change. Can you help?
 
G

Guest

strSQL = "SELECT [v_products_model], [v_products_image] FROM Database-sep"
This is it.
 
D

Douglas J. Steele

That implies that you mistyped the name of one of the fields (or perhaps of
the table).
 
G

Guest

I sure appreciate your time and assistance. It has been so long since I've
had to do any programming that I don't know the language and have for the
most part even forgotten the concepts. I did have a word mistyped. Now,
it's bogging down with a Bad File Name or Number error on the LEN line. Here
is the code as it currently exists. Thanks for any additional help you can
provide!

Private Sub Command4_Click()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strFolder As String
Dim strNewFile As String
Dim strOldFile As String
Dim strSQL As String

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\Documents and Settings\Mike\My Documents\Walfield\LNC Pet
Supply\a-e\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT [v_products_model], [v_products_image] FROM ProductInfo"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr![v_products_model] & ".jpg"
strOldFile = strFolder & rsCurr![v_products_image]
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0 Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

End Sub
 
D

Douglas J. Steele

The error doesn't make sense to me. You can put anything in that statement,
like Len(Dir("xxx")) and it should be fine!

Two possibilities. Do strNewFile and strOldFile contain the correct values?
If so, try

If (Len(Dir(strOldFile)) > 0) And (Len(Dir(strNewFile)) = 0) Then


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Mike said:
I sure appreciate your time and assistance. It has been so long since I've
had to do any programming that I don't know the language and have for the
most part even forgotten the concepts. I did have a word mistyped. Now,
it's bogging down with a Bad File Name or Number error on the LEN line.
Here
is the code as it currently exists. Thanks for any additional help you
can
provide!

Private Sub Command4_Click()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strFolder As String
Dim strNewFile As String
Dim strOldFile As String
Dim strSQL As String

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\Documents and Settings\Mike\My Documents\Walfield\LNC Pet
Supply\a-e\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT [v_products_model], [v_products_image] FROM ProductInfo"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr![v_products_model] & ".jpg"
strOldFile = strFolder & rsCurr![v_products_image]
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0 Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

End Sub

Douglas J. Steele said:
That implies that you mistyped the name of one of the fields (or perhaps
of
the table).
 
G

Guest

Doug,
The revised line worked beautifully. Can't thank you enough.

Douglas J. Steele said:
The error doesn't make sense to me. You can put anything in that statement,
like Len(Dir("xxx")) and it should be fine!

Two possibilities. Do strNewFile and strOldFile contain the correct values?
If so, try

If (Len(Dir(strOldFile)) > 0) And (Len(Dir(strNewFile)) = 0) Then


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Mike said:
I sure appreciate your time and assistance. It has been so long since I've
had to do any programming that I don't know the language and have for the
most part even forgotten the concepts. I did have a word mistyped. Now,
it's bogging down with a Bad File Name or Number error on the LEN line.
Here
is the code as it currently exists. Thanks for any additional help you
can
provide!

Private Sub Command4_Click()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strFolder As String
Dim strNewFile As String
Dim strOldFile As String
Dim strSQL As String

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\Documents and Settings\Mike\My Documents\Walfield\LNC Pet
Supply\a-e\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT [v_products_model], [v_products_image] FROM ProductInfo"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr![v_products_model] & ".jpg"
strOldFile = strFolder & rsCurr![v_products_image]
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0 Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

End Sub

Douglas J. Steele said:
That implies that you mistyped the name of one of the fields (or perhaps
of
the table).

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Actually, the error is "Too few parameters. Expected 1.

:

What's your strSQL look like?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Hey Douglas,

Thanks for the code. I'm getting a syntax error on the -Set rsCurr
=
dbCurr.OpenRecordset(strSQL)-line. I looked at the VB help example,
but
couldn't figure out what I should change. Can you help?

:

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

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\SomeFolder\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT ProductID, ImageID FROM MyTable"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr!ProductID & ".jpg"
strOldFile = strFolder & rsCurr!ImageID
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0 Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

rsCurr.Close
Set rsCurr = Nothing
Set dbCurr = Nothing

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I have an Access database which has records of products. There is
a
product
ID field and a field which gives the name of the associated
product
image.
I
need to rename the image to match the product ID exactly. I'm
sure
there
is
a way to automate this task, but my mind isn't in the right
place.
Can
anyone help?

Product ID Image ID
247654 dogbed.jpg

Image ID must become: 247654.jpg
 
G

Guest

Douglas, thanks again for your help. Two things: 1) Can you suggest a
reference manual that I could use to become familiar with this programming
language? and 2) Can you help me with a smidgeon of code which will look at
the ProductID, match it to the *.jpg file and move that file to a new folder?

In case you're curious, I'm starting an online store, and my supplier's
database doesn't conform with my shopping cart requirements and I'm needing
to manipulate the data for that reason. Thanks
Mike Barefield

Douglas J. Steele said:
The error doesn't make sense to me. You can put anything in that statement,
like Len(Dir("xxx")) and it should be fine!

Two possibilities. Do strNewFile and strOldFile contain the correct values?
If so, try

If (Len(Dir(strOldFile)) > 0) And (Len(Dir(strNewFile)) = 0) Then


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Mike said:
I sure appreciate your time and assistance. It has been so long since I've
had to do any programming that I don't know the language and have for the
most part even forgotten the concepts. I did have a word mistyped. Now,
it's bogging down with a Bad File Name or Number error on the LEN line.
Here
is the code as it currently exists. Thanks for any additional help you
can
provide!

Private Sub Command4_Click()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strFolder As String
Dim strNewFile As String
Dim strOldFile As String
Dim strSQL As String

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\Documents and Settings\Mike\My Documents\Walfield\LNC Pet
Supply\a-e\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT [v_products_model], [v_products_image] FROM ProductInfo"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr![v_products_model] & ".jpg"
strOldFile = strFolder & rsCurr![v_products_image]
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0 Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

End Sub

Douglas J. Steele said:
That implies that you mistyped the name of one of the fields (or perhaps
of
the table).

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Actually, the error is "Too few parameters. Expected 1.

:

What's your strSQL look like?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Hey Douglas,

Thanks for the code. I'm getting a syntax error on the -Set rsCurr
=
dbCurr.OpenRecordset(strSQL)-line. I looked at the VB help example,
but
couldn't figure out what I should change. Can you help?

:

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

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\SomeFolder\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT ProductID, ImageID FROM MyTable"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr!ProductID & ".jpg"
strOldFile = strFolder & rsCurr!ImageID
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0 Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

rsCurr.Close
Set rsCurr = Nothing
Set dbCurr = Nothing

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I have an Access database which has records of products. There is
a
product
ID field and a field which gives the name of the associated
product
image.
I
need to rename the image to match the product ID exactly. I'm
sure
there
is
a way to automate this task, but my mind isn't in the right
place.
Can
anyone help?

Product ID Image ID
247654 dogbed.jpg

Image ID must become: 247654.jpg
 
D

Douglas J. Steele

Jeff Conrad lists a number of good lists of books at
http://home.bendbroadband.com/conradsystems/accessjunkie/resources.html#Books

The Developer's Handbook, at http://www.developershandbook.com/, is the
"bible", but it may not be appropriate if you're just a beginner.

Not sure what you're looking for in the second question. Isn't that what I
already gave you?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Mike said:
Douglas, thanks again for your help. Two things: 1) Can you suggest a
reference manual that I could use to become familiar with this programming
language? and 2) Can you help me with a smidgeon of code which will look
at
the ProductID, match it to the *.jpg file and move that file to a new
folder?

In case you're curious, I'm starting an online store, and my supplier's
database doesn't conform with my shopping cart requirements and I'm
needing
to manipulate the data for that reason. Thanks
Mike Barefield

Douglas J. Steele said:
The error doesn't make sense to me. You can put anything in that
statement,
like Len(Dir("xxx")) and it should be fine!

Two possibilities. Do strNewFile and strOldFile contain the correct
values?
If so, try

If (Len(Dir(strOldFile)) > 0) And (Len(Dir(strNewFile)) = 0) Then


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Mike said:
I sure appreciate your time and assistance. It has been so long since
I've
had to do any programming that I don't know the language and have for
the
most part even forgotten the concepts. I did have a word mistyped.
Now,
it's bogging down with a Bad File Name or Number error on the LEN line.
Here
is the code as it currently exists. Thanks for any additional help you
can
provide!

Private Sub Command4_Click()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strFolder As String
Dim strNewFile As String
Dim strOldFile As String
Dim strSQL As String

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\Documents and Settings\Mike\My Documents\Walfield\LNC
Pet
Supply\a-e\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT [v_products_model], [v_products_image] FROM
ProductInfo"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr![v_products_model] & ".jpg"
strOldFile = strFolder & rsCurr![v_products_image]
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0 Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

End Sub

:

That implies that you mistyped the name of one of the fields (or
perhaps
of
the table).

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Actually, the error is "Too few parameters. Expected 1.

:

What's your strSQL look like?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Hey Douglas,

Thanks for the code. I'm getting a syntax error on the -Set
rsCurr
=
dbCurr.OpenRecordset(strSQL)-line. I looked at the VB help
example,
but
couldn't figure out what I should change. Can you help?

:

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

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\SomeFolder\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT ProductID, ImageID FROM MyTable"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr!ProductID & ".jpg"
strOldFile = strFolder & rsCurr!ImageID
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0
Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

rsCurr.Close
Set rsCurr = Nothing
Set dbCurr = Nothing

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I have an Access database which has records of products. There
is
a
product
ID field and a field which gives the name of the associated
product
image.
I
need to rename the image to match the product ID exactly. I'm
sure
there
is
a way to automate this task, but my mind isn't in the right
place.
Can
anyone help?

Product ID Image ID
247654 dogbed.jpg

Image ID must become: 247654.jpg
 
G

Guest

I'll check out those links. Thank you. The situation that I have now is
that your code has successfully renamed the image files to match the product
number, but there are images in the folder which are not associated with a
product number. To save space on the server, I want to upload only those
image files associated with a product in the Access table. So, I'm looking
to read the product number in the current record set and move the matching
*.jpg file to a new folder. I will then upload from that new folder. Thanks.

Douglas J. Steele said:
Jeff Conrad lists a number of good lists of books at
http://home.bendbroadband.com/conradsystems/accessjunkie/resources.html#Books

The Developer's Handbook, at http://www.developershandbook.com/, is the
"bible", but it may not be appropriate if you're just a beginner.

Not sure what you're looking for in the second question. Isn't that what I
already gave you?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Mike said:
Douglas, thanks again for your help. Two things: 1) Can you suggest a
reference manual that I could use to become familiar with this programming
language? and 2) Can you help me with a smidgeon of code which will look
at
the ProductID, match it to the *.jpg file and move that file to a new
folder?

In case you're curious, I'm starting an online store, and my supplier's
database doesn't conform with my shopping cart requirements and I'm
needing
to manipulate the data for that reason. Thanks
Mike Barefield

Douglas J. Steele said:
The error doesn't make sense to me. You can put anything in that
statement,
like Len(Dir("xxx")) and it should be fine!

Two possibilities. Do strNewFile and strOldFile contain the correct
values?
If so, try

If (Len(Dir(strOldFile)) > 0) And (Len(Dir(strNewFile)) = 0) Then


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I sure appreciate your time and assistance. It has been so long since
I've
had to do any programming that I don't know the language and have for
the
most part even forgotten the concepts. I did have a word mistyped.
Now,
it's bogging down with a Bad File Name or Number error on the LEN line.
Here
is the code as it currently exists. Thanks for any additional help you
can
provide!

Private Sub Command4_Click()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strFolder As String
Dim strNewFile As String
Dim strOldFile As String
Dim strSQL As String

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\Documents and Settings\Mike\My Documents\Walfield\LNC
Pet
Supply\a-e\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT [v_products_model], [v_products_image] FROM
ProductInfo"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr![v_products_model] & ".jpg"
strOldFile = strFolder & rsCurr![v_products_image]
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0 Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

End Sub

:

That implies that you mistyped the name of one of the fields (or
perhaps
of
the table).

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Actually, the error is "Too few parameters. Expected 1.

:

What's your strSQL look like?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Hey Douglas,

Thanks for the code. I'm getting a syntax error on the -Set
rsCurr
=
dbCurr.OpenRecordset(strSQL)-line. I looked at the VB help
example,
but
couldn't figure out what I should change. Can you help?

:

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

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\SomeFolder\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT ProductID, ImageID FROM MyTable"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr!ProductID & ".jpg"
strOldFile = strFolder & rsCurr!ImageID
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0
Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

rsCurr.Close
Set rsCurr = Nothing
Set dbCurr = Nothing

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I have an Access database which has records of products. There
is
a
product
ID field and a field which gives the name of the associated
product
image.
I
need to rename the image to match the product ID exactly. I'm
sure
there
is
a way to automate this task, but my mind isn't in the right
place.
Can
anyone help?

Product ID Image ID
247654 dogbed.jpg

Image ID must become: 247654.jpg
 
D

Douglas J. Steele

Well, assuming that you've got the full path to the picture stored in
strFullPath, you can move it to another folder using the Name function as
well.

The syntax for the Name statement is

Name oldpathname As newpathname

Both newpathname and oldpathname must be on the same drive. If the path in
newpathname exists and is different from the path in oldpathname, the Name
statement moves the file to the new directory or folder and renames the
file, if necessary. If newpathname and oldpathname have different paths and
the same file name, Name moves the file to the new location and leaves the
file name unchanged. Using Name, you can move a file from one directory or
folder to another, but you can't move a directory or folder.

If you do need to move to a different drive, you'd have to use the FileCopy
statement (and then Kill the old file if you don't want to keep it)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Mike said:
I'll check out those links. Thank you. The situation that I have now is
that your code has successfully renamed the image files to match the
product
number, but there are images in the folder which are not associated with a
product number. To save space on the server, I want to upload only those
image files associated with a product in the Access table. So, I'm
looking
to read the product number in the current record set and move the matching
*.jpg file to a new folder. I will then upload from that new folder.
Thanks.

Douglas J. Steele said:
Jeff Conrad lists a number of good lists of books at
http://home.bendbroadband.com/conradsystems/accessjunkie/resources.html#Books

The Developer's Handbook, at http://www.developershandbook.com/, is the
"bible", but it may not be appropriate if you're just a beginner.

Not sure what you're looking for in the second question. Isn't that what
I
already gave you?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Mike said:
Douglas, thanks again for your help. Two things: 1) Can you suggest
a
reference manual that I could use to become familiar with this
programming
language? and 2) Can you help me with a smidgeon of code which will
look
at
the ProductID, match it to the *.jpg file and move that file to a new
folder?

In case you're curious, I'm starting an online store, and my supplier's
database doesn't conform with my shopping cart requirements and I'm
needing
to manipulate the data for that reason. Thanks
Mike Barefield

:

The error doesn't make sense to me. You can put anything in that
statement,
like Len(Dir("xxx")) and it should be fine!

Two possibilities. Do strNewFile and strOldFile contain the correct
values?
If so, try

If (Len(Dir(strOldFile)) > 0) And (Len(Dir(strNewFile)) = 0) Then


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I sure appreciate your time and assistance. It has been so long
since
I've
had to do any programming that I don't know the language and have
for
the
most part even forgotten the concepts. I did have a word mistyped.
Now,
it's bogging down with a Bad File Name or Number error on the LEN
line.
Here
is the code as it currently exists. Thanks for any additional help
you
can
provide!

Private Sub Command4_Click()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strFolder As String
Dim strNewFile As String
Dim strOldFile As String
Dim strSQL As String

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\Documents and Settings\Mike\My
Documents\Walfield\LNC
Pet
Supply\a-e\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT [v_products_model], [v_products_image] FROM
ProductInfo"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr![v_products_model] & ".jpg"
strOldFile = strFolder & rsCurr![v_products_image]
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0 Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

End Sub

:

That implies that you mistyped the name of one of the fields (or
perhaps
of
the table).

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Actually, the error is "Too few parameters. Expected 1.

:

What's your strSQL look like?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Hey Douglas,

Thanks for the code. I'm getting a syntax error on the -Set
rsCurr
=
dbCurr.OpenRecordset(strSQL)-line. I looked at the VB help
example,
but
couldn't figure out what I should change. Can you help?

:

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

' Define what folder the pictures are in.
' Note that the final slash must be there
strFolder = "C:\SomeFolder\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT ProductID, ImageID FROM MyTable"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False
strNewFile = strFolder & rsCurr!ProductID & ".jpg"
strOldFile = strFolder & rsCurr!ImageID
' Make sure that the file pointed to by ImageID exists,
' and that the desired renamed file doesn't exist.
' (You didn't say what you wanted done if the
' desired renamed file does exist!)
If Len(Dir(strOldFile)) > 0 And Len(Dir(strNewFile)) = 0
Then
Name strOldFile As strNewFile
End If
rsCurr.MoveNext
Loop

rsCurr.Close
Set rsCurr = Nothing
Set dbCurr = Nothing

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I have an Access database which has records of products.
There
is
a
product
ID field and a field which gives the name of the associated
product
image.
I
need to rename the image to match the product ID exactly.
I'm
sure
there
is
a way to automate this task, but my mind isn't in the right
place.
Can
anyone help?

Product ID Image ID
247654 dogbed.jpg

Image ID must become: 247654.jpg
 
M

M.Jamal

Hello there!

Could you advise what should be done, if desired rename file already existed
and we wanted a windows dialog box asking for the user permission to
overwrite the old file.

thanks in advance.
 
D

Douglas J. Steele

You can use

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
Name strOldFile As strNewFile
End If
Else
Name strOldFile As strNewFile

End If
End If
 

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