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