fso replacement

R

Ray

I use the following section of code to determine if there is a specific
folder in a location and the second section to see if there is anything in
the folder and how many items are there. It works great in 2003 but creates
an error in 2007. I have heard that 2007 does not support fso. Is there an
alternative to this code that will work? I understand enough to read the code
but not enough to write it myself.


fol = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting Documents\" &
Me.[VCARNum]
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Response

If Not fso.FolderExists(fol) Then
Response = MsgBox("Do you want Access to make a new folder named " &
vbCrLf & _
" " & Me.[VCARNum] & " to store the supporting
documents?", vbYesNo)
If Response = vbYes Then
fso.CreateFolder (fol)
Else
Exit Sub
End If
End If

*****************************

Dim FileNames
Set fs = Application.FileSearch
With fs
.LookIn = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting
Documents\" & Me.[VCARNum]
.FileName = "*.*"
If .Execute > 0 Then
Me.Command44.Caption = .FoundFiles.Count & " Supporting Documents"
Me.Command44.ForeColor = vbBlack
Else
Me.Command44.Caption = "No Supporting Documents"
Me.Command44.ForeColor = vbRed
End If
End With
 
A

Arvin Meyer [MVP]

You will need to set a reference to the WSH (Windows Scripting Host) or
change your code to use late binding (GetObject, instead of CreateObject):

Dim fso As Object
Set fso = GetObject("Scripting.FileSystemObject")
 
D

Daniel Pineault

To check for the existance of a file or folder you can simply use the Dir()
function. To create a folder you can simply use the mkdir function().

Check the help for more information on these.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
N

NG

Hi Ray,

the given code works fine on my version of Access 2007. What's the exact
error message? Maybe you do not have enough rights to create the folder.

grNG
 
R

Ray

I may have accidently misrepresented the issue. It works on Access 2003 and
errors on Runtime 2007. Runtime gives useless error messages and then closes.
When I rem out the code below, the form opens just fine.

NG said:
Hi Ray,

the given code works fine on my version of Access 2007. What's the exact
error message? Maybe you do not have enough rights to create the folder.

grNG

Ray said:
I use the following section of code to determine if there is a specific
folder in a location and the second section to see if there is anything in
the folder and how many items are there. It works great in 2003 but creates
an error in 2007. I have heard that 2007 does not support fso. Is there an
alternative to this code that will work? I understand enough to read the code
but not enough to write it myself.


fol = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting Documents\" &
Me.[VCARNum]
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Response

If Not fso.FolderExists(fol) Then
Response = MsgBox("Do you want Access to make a new folder named " &
vbCrLf & _
" " & Me.[VCARNum] & " to store the supporting
documents?", vbYesNo)
If Response = vbYes Then
fso.CreateFolder (fol)
Else
Exit Sub
End If
End If

*****************************

Dim FileNames
Set fs = Application.FileSearch
With fs
.LookIn = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting
Documents\" & Me.[VCARNum]
.FileName = "*.*"
If .Execute > 0 Then
Me.Command44.Caption = .FoundFiles.Count & " Supporting Documents"
Me.Command44.ForeColor = vbBlack
Else
Me.Command44.Caption = "No Supporting Documents"
Me.Command44.ForeColor = vbRed
End If
End With
 
D

Daniel Pineault

'Useless error messages'? Which ones.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



Ray said:
I may have accidently misrepresented the issue. It works on Access 2003 and
errors on Runtime 2007. Runtime gives useless error messages and then closes.
When I rem out the code below, the form opens just fine.

NG said:
Hi Ray,

the given code works fine on my version of Access 2007. What's the exact
error message? Maybe you do not have enough rights to create the folder.

grNG

Ray said:
I use the following section of code to determine if there is a specific
folder in a location and the second section to see if there is anything in
the folder and how many items are there. It works great in 2003 but creates
an error in 2007. I have heard that 2007 does not support fso. Is there an
alternative to this code that will work? I understand enough to read the code
but not enough to write it myself.


fol = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting Documents\" &
Me.[VCARNum]
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Response

If Not fso.FolderExists(fol) Then
Response = MsgBox("Do you want Access to make a new folder named " &
vbCrLf & _
" " & Me.[VCARNum] & " to store the supporting
documents?", vbYesNo)
If Response = vbYes Then
fso.CreateFolder (fol)
Else
Exit Sub
End If
End If

*****************************

Dim FileNames
Set fs = Application.FileSearch
With fs
.LookIn = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting
Documents\" & Me.[VCARNum]
.FileName = "*.*"
If .Execute > 0 Then
Me.Command44.Caption = .FoundFiles.Count & " Supporting Documents"
Me.Command44.ForeColor = vbBlack
Else
Me.Command44.Caption = "No Supporting Documents"
Me.Command44.ForeColor = vbRed
End If
End With
 
R

Ray

Runtime only has one message for everything. "Runtime has encountered a
problem and will close". Maybe not exact words, but I have never seen
anything different from Runtime no matter the issue.

Daniel Pineault said:
'Useless error messages'? Which ones.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



Ray said:
I may have accidently misrepresented the issue. It works on Access 2003 and
errors on Runtime 2007. Runtime gives useless error messages and then closes.
When I rem out the code below, the form opens just fine.

NG said:
Hi Ray,

the given code works fine on my version of Access 2007. What's the exact
error message? Maybe you do not have enough rights to create the folder.

grNG

:

I use the following section of code to determine if there is a specific
folder in a location and the second section to see if there is anything in
the folder and how many items are there. It works great in 2003 but creates
an error in 2007. I have heard that 2007 does not support fso. Is there an
alternative to this code that will work? I understand enough to read the code
but not enough to write it myself.


fol = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting Documents\" &
Me.[VCARNum]
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Response

If Not fso.FolderExists(fol) Then
Response = MsgBox("Do you want Access to make a new folder named " &
vbCrLf & _
" " & Me.[VCARNum] & " to store the supporting
documents?", vbYesNo)
If Response = vbYes Then
fso.CreateFolder (fol)
Else
Exit Sub
End If
End If

*****************************

Dim FileNames
Set fs = Application.FileSearch
With fs
.LookIn = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting
Documents\" & Me.[VCARNum]
.FileName = "*.*"
If .Execute > 0 Then
Me.Command44.Caption = .FoundFiles.Count & " Supporting Documents"
Me.Command44.ForeColor = vbBlack
Else
Me.Command44.Caption = "No Supporting Documents"
Me.Command44.ForeColor = vbRed
End If
End With
 
R

Ray

This is exactly what Runtime reports

"Exceution of this Application has stopped due to a run-time error.
This Application can't continue and will be shut down"

This is the only error message I have ever seen from Runtime and I make a
lot of errors

If it helps, I have the same code below in the both the On Current and On
Open event of the form.

I can use the Dir function to see if the folder exists (Thankyou for the
suggestion), but what can I use to replace the count of files within the
folder?


Daniel Pineault said:
'Useless error messages'? Which ones.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



Ray said:
I may have accidently misrepresented the issue. It works on Access 2003 and
errors on Runtime 2007. Runtime gives useless error messages and then closes.
When I rem out the code below, the form opens just fine.

NG said:
Hi Ray,

the given code works fine on my version of Access 2007. What's the exact
error message? Maybe you do not have enough rights to create the folder.

grNG

:

I use the following section of code to determine if there is a specific
folder in a location and the second section to see if there is anything in
the folder and how many items are there. It works great in 2003 but creates
an error in 2007. I have heard that 2007 does not support fso. Is there an
alternative to this code that will work? I understand enough to read the code
but not enough to write it myself.


fol = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting Documents\" &
Me.[VCARNum]
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Response

If Not fso.FolderExists(fol) Then
Response = MsgBox("Do you want Access to make a new folder named " &
vbCrLf & _
" " & Me.[VCARNum] & " to store the supporting
documents?", vbYesNo)
If Response = vbYes Then
fso.CreateFolder (fol)
Else
Exit Sub
End If
End If

*****************************

Dim FileNames
Set fs = Application.FileSearch
With fs
.LookIn = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting
Documents\" & Me.[VCARNum]
.FileName = "*.*"
If .Execute > 0 Then
Me.Command44.Caption = .FoundFiles.Count & " Supporting Documents"
Me.Command44.ForeColor = vbBlack
Else
Me.Command44.Caption = "No Supporting Documents"
Me.Command44.ForeColor = vbRed
End If
End With
 
D

Daniel Pineault

Ray,

Do you have error handlers in your procedures? Because I run many dbs in
run-time and my error handling routines return proper error msgboxes. You
should implement it and see how mush it might simplify your life, especially
in troubleshooting such issues.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



Ray said:
This is exactly what Runtime reports

"Exceution of this Application has stopped due to a run-time error.
This Application can't continue and will be shut down"

This is the only error message I have ever seen from Runtime and I make a
lot of errors

If it helps, I have the same code below in the both the On Current and On
Open event of the form.

I can use the Dir function to see if the folder exists (Thankyou for the
suggestion), but what can I use to replace the count of files within the
folder?


Daniel Pineault said:
'Useless error messages'? Which ones.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



Ray said:
I may have accidently misrepresented the issue. It works on Access 2003 and
errors on Runtime 2007. Runtime gives useless error messages and then closes.
When I rem out the code below, the form opens just fine.

:

Hi Ray,

the given code works fine on my version of Access 2007. What's the exact
error message? Maybe you do not have enough rights to create the folder.

grNG

:

I use the following section of code to determine if there is a specific
folder in a location and the second section to see if there is anything in
the folder and how many items are there. It works great in 2003 but creates
an error in 2007. I have heard that 2007 does not support fso. Is there an
alternative to this code that will work? I understand enough to read the code
but not enough to write it myself.


fol = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting Documents\" &
Me.[VCARNum]
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Response

If Not fso.FolderExists(fol) Then
Response = MsgBox("Do you want Access to make a new folder named " &
vbCrLf & _
" " & Me.[VCARNum] & " to store the supporting
documents?", vbYesNo)
If Response = vbYes Then
fso.CreateFolder (fol)
Else
Exit Sub
End If
End If

*****************************

Dim FileNames
Set fs = Application.FileSearch
With fs
.LookIn = "\\mmpdsnas01a\apps$\Quality\Back Ends\VCAR Supporting
Documents\" & Me.[VCARNum]
.FileName = "*.*"
If .Execute > 0 Then
Me.Command44.Caption = .FoundFiles.Count & " Supporting Documents"
Me.Command44.ForeColor = vbBlack
Else
Me.Command44.Caption = "No Supporting Documents"
Me.Command44.ForeColor = vbRed
End If
End With
 

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