Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how call a procedure when you put a file into a folder

Status
Not open for further replies.

ATHUEL

Technical User
Joined
Sep 23, 2002
Messages
29
Location
US
hi everyone,

I want to build an application that open a window when a a new file is loaded into a folder.
I tried to do this using the following,(these functions are in a module)

Public Function FileExist(strPath As String) As Boolean
FileExist = Not (Dir(strPath) = "")
End Function

Public Function file_in_folder() As Boolean


Dim sFilePath As String

sFilePath = "c:\abcdef\"


If (FileExist(sFilePath & "*.*")) Then
file_in_folder = True
Form1.Visible = True

Else

file_in_folder = False

End If
End Function

Now, i call to file_in_folder( ) function throught a "do while/ loop" procedure in order to wait until something happens inside the folder but i can´t achieve that the window appears when a file is loaded into the "abcdef" folder.
it always stay "waiting".
But if the file is in the folder before i run the appl. then when it runs the window is open.
then i put a msgbox inside function, like this

Public Function file_in_folder() As Boolean


Dim sFilePath As String

sFilePath = "c:\abcdef\"


If (FileExist(sFilePath & "*.*")) Then
file_in_folder = True
msgbox "file in folder"
Form1.Visible = True

Else

file_in_folder = False
msgbox "file does not exist"
End If
End Function

and it works fine, but i don´t want this mesage.
Can anyone helpme with this?
I only want run the appl. when a file is inside a folder...
 
You probably need a DoEvents statement in your Do/While loop. Without it, the program will lock up in that loop, because it cannot see the file appear. I got it to work fine like this.


Dim present As Boolean

Do While present = False

present = file_in_folder
DoEvents

Loop
 
ok,
i tried your suggestion but it doesn´t work yet.
i´m writing this code onto a form_load, maybe here is the problem?
in that case what kind of event could i use?
 
I would put the Do While loop into a Sub_Main proceedure in your module, and have the program execute the Sub_Main as the startup instead of your form. ( the Form1.Visible line will load the form, because you referred to a property of the form in code, but you should really use "Load Form1" instead.

Robert
 
ok, thanks!!
I gonna try this, and i´ll let you know how it works
 
thanks Vampire !!!
It works really well!!
this is the code i used ...maybe it helps someone else.

Code:
Sub main()
  Dim present As Boolean

Do While present = False

present = file_in_folder
DoEvents

Loop
Form1.Show
                        
End Sub

Public Function FileExist(strPath As String) As Boolean

FileExist = Not (Dir(strPath) = "")

End Function

Public Function file_in_folder() As Boolean

Dim sFilePath As String

sFilePath = "c:\myfolder\"

If (FileExist(sFilePath & "*.*")) Then

file_in_folder = True

Else

file_in_folder = False

End If

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top