Use access to rename / overwrite image files.

M

M.Jamal

Hello there!

I am using the following code succesfully to rename and move the selected
image file. ( Code courtesy of Mr. Douglas J. Steele in this group and i
modified it a litle bit.)

Private Sub Command12_Click()

Dim dbCurr As DAO.Database
Dim qdf As QueryDef
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 = "Z:\Products Database Photos\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT [Products].Item No, [Products].tempfilelocation" & " " & _
"FROM [Products]" & " " & _
"WHERE (((Products.[Item No])=[Forms]![Add Product]![Item No]));"

Set dbCurr = CurrentDb()
Set qdf = dbCurr.QueryDefs("Query1")
qdf.Parameters("[Forms]![Add Product]![Item No]") = [Forms]![Add
Product]![Item No]
Set rsCurr = qdf.OpenRecordset
Do While rsCurr.EOF = False


strNewFile = strFolder & rsCurr![Item No] & ".jpg"
strOldFile = [tempfilelocation]
' 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


In case when the desired rename image exists, i want to show up a windows
file overwrite confirmation box and ask for the user approval, if clicked
yes, the old file must be overwritten by the new file.

any ideas!!

Thanks in advance.
 
P

pietlinden

Hello there!

I am using the following code succesfully to rename and move the selected
image file. ( Code courtesy of Mr. Douglas J. Steele in this group and i
modified it a litle bit.)

Private Sub Command12_Click()

Dim dbCurr As DAO.Database
Dim qdf As QueryDef
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 = "Z:\Products Database Photos\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT [Products].Item No, [Products].tempfilelocation" & " "& _
        "FROM [Products]" & " " & _
        "WHERE (((Products.[Item No])=[Forms]![Add Product]![Item No]));"

Set dbCurr = CurrentDb()
Set qdf = dbCurr.QueryDefs("Query1")
qdf.Parameters("[Forms]![Add Product]![Item No]") = [Forms]![Add
Product]![Item No]
Set rsCurr = qdf.OpenRecordset
Do While rsCurr.EOF = False

strNewFile = strFolder & rsCurr![Item No] & ".jpg"
strOldFile = [tempfilelocation]
' 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

In case when the desired rename image exists, i want to show up a windows
file overwrite confirmation box and ask for the user approval, if clicked
yes, the old file must be overwritten by the new file.

any ideas!!

Thanks in advance.

use an If statement and then the MessageBox function to prompt the
user.

if MsgBox("Overwrite old file?",vbYesNo)=vbYes Then
'do the Rename thing
else
'do something else
End If
 
M

M.Jamal

thanks for the answer, i am going to work on it.

Just a little bit more effort, can you please put it in the code below. I
really am new to VB.

If (Len(Dir(strOldFile)) > 0) And (Len(Dir(strNewFile)) = 0) Then
Many thanks in advance !

Hello there!

I am using the following code succesfully to rename and move the selected
image file. ( Code courtesy of Mr. Douglas J. Steele in this group and i
modified it a litle bit.)

Private Sub Command12_Click()

Dim dbCurr As DAO.Database
Dim qdf As QueryDef
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 = "Z:\Products Database Photos\"

' Define the SQL to get the data from the table.
' (Change the field and table names as required)
strSQL = "SELECT [Products].Item No, [Products].tempfilelocation" & " " & _
"FROM [Products]" & " " & _
"WHERE (((Products.[Item No])=[Forms]![Add Product]![Item No]));"

Set dbCurr = CurrentDb()
Set qdf = dbCurr.QueryDefs("Query1")
qdf.Parameters("[Forms]![Add Product]![Item No]") = [Forms]![Add
Product]![Item No]
Set rsCurr = qdf.OpenRecordset
Do While rsCurr.EOF = False

strNewFile = strFolder & rsCurr![Item No] & ".jpg"
strOldFile = [tempfilelocation]
' 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

In case when the desired rename image exists, i want to show up a windows
file overwrite confirmation box and ask for the user approval, if clicked
yes, the old file must be overwritten by the new file.

any ideas!!

Thanks in advance.

use an If statement and then the MessageBox function to prompt the
user.

if MsgBox("Overwrite old file?",vbYesNo)=vbYes Then
'do the Rename thing
else
'do something else
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