Folder

Jpernice

Board Regular
Joined
Mar 23, 2010
Messages
117
<HR style="BACKGROUND-COLOR: #ffffff; COLOR: #ffffff" SIZE=1> <!-- / icon and title --><!-- message -->
Hello

I am getting error message cannot end sub
Please help if possible

Dim file1 As Object
Dim filecount1 As Long

With CreateObject("Scripting.FileSystemObject").GetFolder("P:\")

For Each file In .Files

If file.Name Like "*" Then

filecount1 = filecount + 1
End If
Next file
End With

Strbodytext2 = "Option 2"
Strbodytext1 = "Option 1"

If filecount1 = 0 Then

DoCmd.SendObject , "", "", "", "", "Jonathan Pernice", "Test", Strbodytext1, False, ""

Else

DoCmd.SendObject , "", "", "", "", "Jonathan Pernice", "Test", Strbodytext2, False, ""

End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
It looks like you need End If before the End Sub.

BTW, it's much easier to read the code if you wrap it in CODE tags.
Without the spaces it's [ CODE ] to start and [ /CODE ] to end.

Denis
 
Upvote 0
Hello

After adding end if. I still am getting a error message.

Error messages

Compile error :

For without next

Thanks

Private Sub Command0_Click()
Dim file1 As Object
Dim filecount1 As Long

With CreateObject("Scripting.FileSystemObject").GetFolder("P:\")

For Each file In .Files

If file.Name Like "*" Then

filecount1 = filecount + 1
End If

If filecount1 = 0 Then
Strbodytext2 = "Option 2"
Strbodytext1 = "Option 1"
DoCmd.SendObject , "", "", "", "", "Jonathan Pernice", "Test", Strbodytext1, False, ""
Else
DoCmd.SendObject , "", "", "", "", "Jonathan Pernice", "Test", Strbodytext2, False, ""
End If
End Sub
 
Upvote 0
Hello

After working on my code I got it working. my issues is now when I have recordd in the folder it work fine. When I do not have records it doesn't pull the second message up

Thanks

Private Sub Command0_Click()
Dim file1 As Object
Dim filecount1 As Long

With CreateObject("Scripting.FileSystemObject").GetFolder("P:")
For Each file In .Files

If file.Name Like "*" Then

filecount1 = filecount + 1
End If
Next file
End With

If filecount1 >= 0 Then
Strbodytext1 = "Option 1"
Strbodytext2 = "Option 2"

DoCmd.SendObject , "", "", "", "", "Jonathan Pernice", "Test", Strbodytext1, False, ""

Else


DoCmd.SendObject , "", "", "", "", "Jonathan Pernice", "Test", Strbodytext2, False, ""
End If
End Sub
 
Upvote 0
I would get a file count first, then proceed only if there are files (or simply set the file count to 0 and send the message that there are no files). Also, Like "*" is unneeded - any file is Like "*".

I don't use SendObject very much. What object are you sending?
 
Upvote 0
Hello

I am sent the user a email letting them know to print the files in folder.
I also am getting the error when deleting Like "*".

if there is no file they
option 1
if there is
option 1

Thanks
 
Upvote 0
I'm not sure of the logic of your code because this line seems to mean you get the same result no matter what happens:
If filecount1 >= 0 Then
Strbodytext1 = "Option 1"
Strbodytext2 = "Option 2"
also there is a problem in that your variables don't match the same names as those you've dimmed (filecount1 vs. filecount; file1 vs. file)

-------------------------------------------------------

If I'm going to guess at what you're trying to do, it's this:
Code:
[COLOR="Navy"]Private[/COLOR] [COLOR="Navy"]Sub[/COLOR] Command0_Click()
[COLOR="Navy"]Dim[/COLOR] FSO [COLOR="Navy"]As[/COLOR] FileSystemObject
[COLOR="Navy"]Dim[/COLOR] strBodyText [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]


    [COLOR="SeaGreen"]'//Create Object[/COLOR]
    [COLOR="Navy"]Set[/COLOR] FSO = CreateObject("Scripting.FileSystemObject")
    
    [COLOR="SeaGreen"]'//Get Count of Files in P:\[/COLOR]
    [COLOR="Navy"]If[/COLOR] FSO.GetFolder("P:\").Files.Count > 0 [COLOR="Navy"]Then[/COLOR]
        strBodyText = "Option 1"
    [COLOR="Navy"]Else[/COLOR]
        strBodyText = "Option 2"
    [COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
    
    [COLOR="SeaGreen"]'//Send Message[/COLOR]
    DoCmd.SendObject , "", "", "", "", _
        "Jonathan Pernice", "Test", strBodyText, False, ""


[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top