Help with IF THEN ELSE code

O

Orga Hades

Greetings.

I need some assistance in determining the proper code for a Word macro I’ve written. Here’s the basic set-up.
I have a user form that contains six image boxes. Below each image is a text box, and above the image is a label. When I click the label an “Open file” window appears and I can then choose a .jpg file to appear into the image box. The name of the file then appears in the text box.

So far so simple.

I also have another text box into which I will type a word(boat, for instance). Then when I click a command button the six .jpg files will be renamed to the word ‘boat’ and numbered sequentially (boat_001, boat_002, boat_003, etc.), then copied into another folder.

This macro works wonderfully… unless one of the image boxes and corresponding text box is left blank, in which case I get the ominous “path not found” error. I know I need to create some sort of “IF THEN ELSE” statement, but I don’t know enough about programming to code it myself.

Would anybody be willing to help me out with this one? Here is the code for the command button:

Private Sub command_photos_Click()

Dim strUnprocessedPhotos As String
Dim strReadyToSell As String

strUnprocessedPhotos = "C:\unprocessed photos”
strReadyToSell = "C:\ready to sell\" & text_master_file.Text

FileCopy strUnprocessedPhotos & text_photos1_filepath.Text, strReadyToSell & "_001.jpg"
FileCopy strUnprocessedPhotos & text_photos2_filepath.Text, strReadyToSell & "_002.jpg"
FileCopy strUnprocessedPhotos & text_photos3_filepath.Text, strReadyToSell & "_003.jpg"
FileCopy strUnprocessedPhotos & text_photos4_filepath.Text, strReadyToSell & "_004.jpg"
FileCopy strUnprocessedPhotos & text_photos5_filepath.Text, strReadyToSell & "_005.jpg"
FileCopy strUnprocessedPhotos & text_photos6_filepath.Text, strReadyToSell & "_006.jpg"

End Sub

Any assistance at all would be honorably appreciated!

Thanks!

-Orga



--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-
 
M

macropod

Hi Orga,

Try:
Private Sub command_photos_Click()
Dim strUnprocessedPhotos As String
Dim strReadyToSell As String
Dim i as Integer
strUnprocessedPhotos = "C:\unprocessed photos"
strReadyToSell = "C:\ready to sell\" & text_master_file.Text
If Dir strUnprocessedPhotos <> "" And Dir text_photos1_filepath <> "" Then
For i = 1 to 6
FileCopy strUnprocessedPhotos & text_photos1_filepath.Text, strReadyToSell & "_00" & i &".jpg"
Next
End If
End Sub

Cheers
 

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