Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Help with IF THEN ELSE code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Orga Hades - 18 Mar 2008 06:34 GMT
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
macropod - 18 Mar 2008 09:01 GMT
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
Signature

macropod
[MVP - Microsoft Word]
-------------------------

> Greetings.
>
[quoted text clipped - 41 lines]
> ------=  Binary Usenet downloading made easy =---------
> -=  Get GrabIt for free from http://www.shemes.com/  =-
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.