只有硬核GURUS - 早期与晚期绑定问题 [英] HARD-CORE GURUS ONLY - Early Vs Late Binding question
问题描述
我需要在项目中使用后期绑定,因为它的公司标准
不包含不是MS默认值的引用,所以我不能添加
脚本运行时。
我需要能够在文件夹(和子转发器)中搜索文件名,
然后复制该文件到指定的目录(目前它是
C:\ TempCD但后来会改变。
我到目前为止所有是以下,我相信我的主要问题是解决
是要弄清楚如何到达子文件夹:
私有函数CheckFile(strPath As String )
Dim FrmScreen作为Form_ScrMainScreens
Dim X作为整数
DoCmd.Hourglass True
Set FrmScreen = Scr(mvFormId)
Dim db作为数据库
Dim rec As dao.Recordset
Dim ICN_Name As String
Dim G,Y,z作为Variant
Dim cnn As New ADODB.Connection
Dim rst as New ADODB.Recordset
设置cnn = CodeProject.Connection
如果Len(strPath)< 3然后
strPath =
" \\Cca-audit \dfs-dc-01 \ Imaging \Client \Out\CMS \ MedicalRecords \"
结束如果
Dim filFile As Object,fdrFolder As Object,fdrSubFolder As Object
Dim fsoSysObj As Object,FL As Object,FLS As Object
设置z = fsoSysObj.Drives(" Y")
设置fdrFolder = z.RootFolder
如果fsoSysObj.FolderExists(strPath)那么
MsgBox我在这里
Else
MsgBox" Failed"
设置G = fsoSysObj.GetFolder(strPath) .Files
每个FL在G
Debug.Print(FL.Path)
下一个FL
''这就是它死的地方
设置Y = G.getSubFolders
每个FL在Y
Debug.Print(FL.Name)
下一页FL
套装fdrFolder = fsoSysObj.GetFolder(strPath).subfolder
设置fdrFolder = CreateObject(" Scripting.Folder")
设置fdrSubFolder = CreateObject(" Scripting.Folder")
设置filFile = CreateObject(" Scripting.File")
如果Len(strPath)< 3然后
strPath =
" \\Cca-audit \dfs-dc-01 \ Imaging \Client \Out\CMS \ MedicalRecords \"
结束如果
G = 0到X - 1
ICN_Name = CmboMulti.List(G )
''*********************************** ************** ****
''********************** **************************** ****
''此过程返回目录中的所有文件进入
''一个Dictionary对象。如果递归调用,它也返回
''子文件夹中的所有文件。
''循环文件集合
For each filFile in fdrFolder.Files
if filFile.Name = ICN_Name& " .PDF"然后
fsoSysObj.copyfile filFile.Path," C:\ TempCD \"
结束如果
下一个filFile >
每个fdrSubFolder在fdrFolder.SubFolders中
Y = CheckFile2(fdrSubFolder.Path,ICN_Name)
如果Y = True那么
GoTo FDRSRCH
结束如果
下一个fdrSubFolder
''********* **************************************** ****
FDRSRCH:
下一页G
MsgBox"医疗申请表格已复制到C:\ TempCD \"
对于G = 0到X - 1
DoCmd.SetWarnings True
MsgBox"右键单击报告正文并打印到PDF。请记住在ICN#之后加上
包括CC以区分CC表和
医疗申请表。
DoCmd .OpenReportrptAdmin_CcWorksheet,acViewPreview,Icn =''" &
CmboMulti.List(G)& "''",acDialog
下一页G
cnn.Close
设置cnn = Nothing
< br $>
DoCmd.Hourglass False
结束函数
私函数CheckFile2(strPath As String,ICN_Name As String)As
Variant
Dim FrmScreen作为Form_ScrMainScreens
Dim X作为整数
DoCmd.Hourglass True
设置FrmScreen = Scr(mvFormId)
Dim db作为数据库
Dim rec As dao.Recordset
Dim G As Variant
Dim cnn As New ADODB.Connection
Dim rst as new ADODB.Recordset
Set cnn = CodeProject.Connection
设置fsoSysObj = CreateObject(" Scripting.FileSystemObject")
设置fdrFolder = CreateObject(" Scripting.Folder")
设置fdrSubFolder = CreateObject(" Scripting.Folder")
设置filFile = CreateObject(" Scripting.File")
如果是Len(strPath) )&l吨; 3然后
strPath =
" \\Cca-audit \dfs-dc-01 \ Imaging \Client \Out\CMS \ MedicalRecords \
结束如果
For each filFile in fdrFolder.Files
if filFile.Name = ICN_Name& " .PDF"然后
fsoSysObj.copyfile filFile.Path," C:\ TempCD \"
CheckFile2 =" True"
GoTo FDRSRCH
结束如果
下一个filFile
每个fdrSubFolder在fdrFolder.SubFolders中
调用CheckFile2 (fdrSubFolder.Path,ICN_Name)
下一个fdrSubFolder
FDRSRCH:
结束功能
I need to use late binding in a project because it''s company standard
to not include references which aren''t MS defaults, so I can''t add the
scripting runtime.
I need to be able to search folders (and sub-forders) for a file name,
and then copy the file to a specified directory (at the moment it''s
C:\TempCD but that will change later.
All I have so far is the following, I believe my main issue to tackle
is to figure out how to get to sub-folders:
Private Function CheckFile(strPath As String)
Dim FrmScreen As Form_ScrMainScreens
Dim X As Integer
DoCmd.Hourglass True
Set FrmScreen = Scr(mvFormId)
Dim db As Database
Dim rec As dao.Recordset
Dim ICN_Name As String
Dim G, Y, z As Variant
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Set cnn = CodeProject.Connection
If Len(strPath) < 3 Then
strPath =
"\\Cca-audit\dfs-dc-01\Imaging\Client\Out\CMS\MedicalRecords\"
End If
Dim filFile As Object, fdrFolder As Object, fdrSubFolder As Object
Dim fsoSysObj As Object, FL As Object, FLS As Object
Set fsoSysObj = CreateObject("Scripting.FileSystemObject")
Set z = fsoSysObj.Drives("Y")
Set fdrFolder = z.RootFolder
If fsoSysObj.FolderExists(strPath) Then
MsgBox "Im here"
Else
MsgBox "Failed"
End If
Set G = fsoSysObj.GetFolder(strPath).Files
For Each FL In G
Debug.Print (FL.Path)
Next FL
''THIS IS WHERE IT DIES
Set Y = G.getSubFolders
For Each FL In Y
Debug.Print (FL.Name)
Next FL
Set fdrFolder = fsoSysObj.GetFolder(strPath).subfolder
Set fdrFolder = CreateObject("Scripting.Folder")
Set fdrSubFolder = CreateObject("Scripting.Folder")
Set filFile = CreateObject("Scripting.File")
If Len(strPath) < 3 Then
strPath =
"\\Cca-audit\dfs-dc-01\Imaging\Client\Out\CMS\MedicalRecords\"
End If
For G = 0 To X - 1
ICN_Name = CmboMulti.List(G)
''************************************************* ****
''************************************************* ****
'' This procedure returns all the files in a directory into
'' a Dictionary object. If called recursively, it also returns
'' all files in subfolders.
'' Loop through Files collection
For Each filFile In fdrFolder.Files
If filFile.Name = ICN_Name & ".pdf" Then
fsoSysObj.copyfile filFile.Path, "C:\TempCD\"
End If
Next filFile
For Each fdrSubFolder In fdrFolder.SubFolders
Y = CheckFile2(fdrSubFolder.Path, ICN_Name)
If Y = True Then
GoTo FDRSRCH
End If
Next fdrSubFolder
''************************************************* ****
FDRSRCH:
Next G
MsgBox "Medical Request Forms have been copied to C:\TempCD\"
For G = 0 To X - 1
DoCmd.SetWarnings True
MsgBox "Right-Click on the report body and print to PDF. Remember to
include ''CC'' after the ICN # to differentiate between the CC Sheet and
Medical Request Forms."
DoCmd.OpenReport "rptAdmin_CcWorksheet", acViewPreview, , "Icn = ''" &
CmboMulti.List(G) & "''", acDialog
Next G
cnn.Close
Set cnn = Nothing
DoCmd.Hourglass False
End Function
Private Function CheckFile2(strPath As String, ICN_Name As String) As
Variant
Dim FrmScreen As Form_ScrMainScreens
Dim X As Integer
DoCmd.Hourglass True
Set FrmScreen = Scr(mvFormId)
Dim db As Database
Dim rec As dao.Recordset
Dim G As Variant
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Set cnn = CodeProject.Connection
Set fsoSysObj = CreateObject("Scripting.FileSystemObject")
Set fdrFolder = CreateObject("Scripting.Folder")
Set fdrSubFolder = CreateObject("Scripting.Folder")
Set filFile = CreateObject("Scripting.File")
If Len(strPath) < 3 Then
strPath =
"\\Cca-audit\dfs-dc-01\Imaging\Client\Out\CMS\MedicalRecords\"
End If
For Each filFile In fdrFolder.Files
If filFile.Name = ICN_Name & ".pdf" Then
fsoSysObj.copyfile filFile.Path, "C:\TempCD\"
CheckFile2 = "True"
GoTo FDRSRCH
End If
Next filFile
For Each fdrSubFolder In fdrFolder.SubFolders
Call CheckFile2(fdrSubFolder.Path, ICN_Name)
Next fdrSubFolder
FDRSRCH:
End Function
推荐答案
这里有一个函数演示如何递归列出文件(没有
使用任何外部引用):
http://allenbrowne.com/ser-59.html
它的行为与脚本的行为略有不同,因为它将
zip文件标识为文件,而不是无法列出它们或列出它们的
内容。
-
Allen Browne - 微软MVP。西澳大利亚州珀斯。
访问用户提示 - http:// allenbrowne.com/tips.html
回复群组,而不是mvps dot org的allenbrowne。
" ManningFan" < ma ******** @ gmail.comwrote in message
news:11 ********************** @ h48g2000cwc.googlegr oups.com ...
There is a function demonstrating how to list files recursively (without
using any external references) here:
http://allenbrowne.com/ser-59.html
It behaves a little differently than the scripting does, as it identifies
zip files as files instead of failing to list them or listing their
contents.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"ManningFan" <ma********@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>我需要在项目中使用后期绑定,因为它的公司标准是
不包括不是MS默认值的引用,所以我不能添加
脚本运行时。
我需要能够搜索文件夹(和子执行器)的文件名,
然后将文件复制到指定的目录(此时它是
C:\\ \\TempCD但稍后会改变。
到目前为止,我所有的以下内容,我相信我要解决的主要问题是
是弄清楚如何转到子文件夹:
私有函数CheckFile(strPath As String)
Dim FrmScreen As Form_ScrMainScreens
Dim X As Integer
DoCmd.Hourglass True
设置FrmScreen = Scr(mvFormId)
Dim db As Database
Dim rec As dao.Recordset
Dim ICN_Name As String
Dim G,Y,z As Variant
Dim cnn As New ADODB.Connection
Dim rst as new ADODB.Recordset
设置cnn = CodeProject.Connection
如果Len( strPath)< 3然后
strPath =
" \\Cca-audit \dfs-dc-01 \ Imaging \Client \Out\CMS \ MedicalRecords \"
结束如果
Dim filFile As Object,fdrFolder As Object,fdrSubFolder As Object
Dim fsoSysObj As Object,FL As Object,FLS As Object
设置z = fsoSysObj.Drives(" Y")
设置fdrFolder = z.RootFolder
如果fsoSysObj.FolderExists(strPath)那么
MsgBox我在这里 ;
Else
MsgBox失败
结束如果
设置G = fsoSysObj。 GetFolder(strPath).Files
每个FL在G
Debug.Print(FL.Path)
下一个FL
''这就是它死的地方
设置Y = G.getSubFolders
每个FL在Y
Debug.Print(FL.Na me)
下一页FL
设置fdrFolder = fsoSysObj.GetFolder(strPath).subfolder
设置fdrFolder = CreateObject(" Scripting.Folder")
设置fdrSubFolder = CreateObject(" Scripting.Folder")
设置filFile = CreateObject(" Scripting.File")
如果Len(strPath)< 3然后
strPath =
" \\Cca-audit \dfs-dc-01 \ Imaging \Client \Out\CMS \ MedicalRecords \"
结束如果
G = 0到X - 1
ICN_Name = CmboMulti.List(G )
''*********************************** ************** ****
''********************** **************************** ****
''此过程返回目录中的所有文件进入
''一个Dictionary对象。如果递归调用,它也返回
''子文件夹中的所有文件。
''循环文件集合
For each filFile in fdrFolder.Files
if filFile.Name = ICN_Name& " .PDF"然后
fsoSysObj.copyfile filFile.Path," C:\ TempCD \"
结束如果
下一个filFile >
每个fdrSubFolder在fdrFolder.SubFolders中
Y = CheckFile2(fdrSubFolder.Path,ICN_Name)
如果Y = True那么
GoTo FDRSRCH
结束如果
下一个fdrSubFolder
''********* **************************************** ****
FDRSRCH:
下一页G
MsgBox"医疗申请表格已复制到C:\ TempCD \"
对于G = 0到X - 1
DoCmd.SetWarnings True
MsgBox"右键单击报告正文并打印到PDF。请记住在ICN#之后加上
包括CC以区分CC表和
医疗申请表。
DoCmd .OpenReportrptAdmin_CcWorksheet,acViewPreview,Icn =''" &
CmboMulti.List(G)& "''",acDialog
下一页G
cnn.Close
设置cnn = Nothing
< br $>
DoCmd.Hourglass False
结束函数
私函数CheckFile2(strPath As String,ICN_Name As String)As
Variant
Dim FrmScreen作为Form_ScrMainScreens
Dim X作为整数
DoCmd.Hourglass True
设置FrmScreen = Scr(mvFormId)
Dim db作为数据库
Dim rec As dao.Recordset
Dim G As Variant
Dim cnn As New ADODB.Connection
Dim rst as new ADODB.Recordset
Set cnn = CodeProject.Connection
设置fsoSysObj = CreateObject(" Scripting.FileSystemObject")
设置fdrFolder = CreateObject(" Scripting.Folder")
设置fdrSubFolder = CreateObject(" Scripting.Folder")
设置filFile = CreateObject(" Scripting.File")
如果Len(str)路径)< 3然后
strPath =
" \\Cca-audit \dfs-dc-01 \ Imaging \Client \Out\CMS \ MedicalRecords \
结束如果
For each filFile in fdrFolder.Files
if filFile.Name = ICN_Name& " .PDF"然后
fsoSysObj.copyfile filFile.Path," C:\ TempCD \"
CheckFile2 =" True"
GoTo FDRSRCH
结束如果
下一个filFile
每个fdrSubFolder在fdrFolder.SubFolders中
调用CheckFile2 (fdrSubFolder.Path,ICN_Name)
下一个fdrSubFolder
FDRSRCH:
结束函数
>I need to use late binding in a project because it''s company standard
to not include references which aren''t MS defaults, so I can''t add the
scripting runtime.
I need to be able to search folders (and sub-forders) for a file name,
and then copy the file to a specified directory (at the moment it''s
C:\TempCD but that will change later.
All I have so far is the following, I believe my main issue to tackle
is to figure out how to get to sub-folders:
Private Function CheckFile(strPath As String)
Dim FrmScreen As Form_ScrMainScreens
Dim X As Integer
DoCmd.Hourglass True
Set FrmScreen = Scr(mvFormId)
Dim db As Database
Dim rec As dao.Recordset
Dim ICN_Name As String
Dim G, Y, z As Variant
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Set cnn = CodeProject.Connection
If Len(strPath) < 3 Then
strPath =
"\\Cca-audit\dfs-dc-01\Imaging\Client\Out\CMS\MedicalRecords\"
End If
Dim filFile As Object, fdrFolder As Object, fdrSubFolder As Object
Dim fsoSysObj As Object, FL As Object, FLS As Object
Set fsoSysObj = CreateObject("Scripting.FileSystemObject")
Set z = fsoSysObj.Drives("Y")
Set fdrFolder = z.RootFolder
If fsoSysObj.FolderExists(strPath) Then
MsgBox "Im here"
Else
MsgBox "Failed"
End If
Set G = fsoSysObj.GetFolder(strPath).Files
For Each FL In G
Debug.Print (FL.Path)
Next FL
''THIS IS WHERE IT DIES
Set Y = G.getSubFolders
For Each FL In Y
Debug.Print (FL.Name)
Next FL
Set fdrFolder = fsoSysObj.GetFolder(strPath).subfolder
Set fdrFolder = CreateObject("Scripting.Folder")
Set fdrSubFolder = CreateObject("Scripting.Folder")
Set filFile = CreateObject("Scripting.File")
If Len(strPath) < 3 Then
strPath =
"\\Cca-audit\dfs-dc-01\Imaging\Client\Out\CMS\MedicalRecords\"
End If
For G = 0 To X - 1
ICN_Name = CmboMulti.List(G)
''************************************************* ****
''************************************************* ****
'' This procedure returns all the files in a directory into
'' a Dictionary object. If called recursively, it also returns
'' all files in subfolders.
'' Loop through Files collection
For Each filFile In fdrFolder.Files
If filFile.Name = ICN_Name & ".pdf" Then
fsoSysObj.copyfile filFile.Path, "C:\TempCD\"
End If
Next filFile
For Each fdrSubFolder In fdrFolder.SubFolders
Y = CheckFile2(fdrSubFolder.Path, ICN_Name)
If Y = True Then
GoTo FDRSRCH
End If
Next fdrSubFolder
''************************************************* ****
FDRSRCH:
Next G
MsgBox "Medical Request Forms have been copied to C:\TempCD\"
For G = 0 To X - 1
DoCmd.SetWarnings True
MsgBox "Right-Click on the report body and print to PDF. Remember to
include ''CC'' after the ICN # to differentiate between the CC Sheet and
Medical Request Forms."
DoCmd.OpenReport "rptAdmin_CcWorksheet", acViewPreview, , "Icn = ''" &
CmboMulti.List(G) & "''", acDialog
Next G
cnn.Close
Set cnn = Nothing
DoCmd.Hourglass False
End Function
Private Function CheckFile2(strPath As String, ICN_Name As String) As
Variant
Dim FrmScreen As Form_ScrMainScreens
Dim X As Integer
DoCmd.Hourglass True
Set FrmScreen = Scr(mvFormId)
Dim db As Database
Dim rec As dao.Recordset
Dim G As Variant
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Set cnn = CodeProject.Connection
Set fsoSysObj = CreateObject("Scripting.FileSystemObject")
Set fdrFolder = CreateObject("Scripting.Folder")
Set fdrSubFolder = CreateObject("Scripting.Folder")
Set filFile = CreateObject("Scripting.File")
If Len(strPath) < 3 Then
strPath =
"\\Cca-audit\dfs-dc-01\Imaging\Client\Out\CMS\MedicalRecords\"
End If
For Each filFile In fdrFolder.Files
If filFile.Name = ICN_Name & ".pdf" Then
fsoSysObj.copyfile filFile.Path, "C:\TempCD\"
CheckFile2 = "True"
GoTo FDRSRCH
End If
Next filFile
For Each fdrSubFolder In fdrFolder.SubFolders
Call CheckFile2(fdrSubFolder.Path, ICN_Name)
Next fdrSubFolder
FDRSRCH:
End Function
" Allen Browne" < Al ********* @ SeeSig.Invalidwrote in
news:44 ********************** *@per-qv1-newsreader-01.iinet.net.au:
"Allen Browne" <Al*********@SeeSig.Invalidwrote in
news:44***********************@per-qv1-newsreader-01.iinet.net.au:
有一个函数演示如何递归列出文件
(不使用任何外部参考资料):
http://allenbrowne.com /ser-59.html
它的行为与脚本有点不同,因为它将bx文件标识为文件而不是失败列出他们或
列出他们的内容。
There is a function demonstrating how to list files recursively
(without using any external references) here:
http://allenbrowne.com/ser-59.html
It behaves a little differently than the scripting does, as it
identifies zip files as files instead of failing to list them or
listing their contents.
除了好的参考,FSO根本不能用于后期
绑定吗?
-
David W. Fenton http://www.dfenton .com /
usenet at dfenton dot com http ://www.dfenton.com/DFA/
是的,可能它的主要使用地点是脚本编写,你不要有
任何其他选择。
-
Terry Kreft
" ; David W. Fenton < XX ******* @ dfenton.com.invalidwrote in message
news:Xn ********************* *************@127.0.0。 1 ...
Yes, probably it''s main place of use is in scripting where you don''t have
any other choice.
--
Terry Kreft
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in message
news:Xn**********************************@127.0.0. 1...
" Allen Browne" < Al ********* @ SeeSig.Invalidwrote in
news:44 ********************** *@per-qv1-newsreader-01.iinet.net.au:
"Allen Browne" <Al*********@SeeSig.Invalidwrote in
news:44***********************@per-qv1-newsreader-01.iinet.net.au:
有一个函数演示如何递归列出文件
(不使用任何外部参考资料):
http://allenbrowne.com /ser-59.html
它的行为与脚本有点不同,因为它将bx文件标识为文件而不是失败列出他们或
列出他们的内容。
There is a function demonstrating how to list files recursively
(without using any external references) here:
http://allenbrowne.com/ser-59.html
It behaves a little differently than the scripting does, as it
identifies zip files as files instead of failing to list them or
listing their contents.
除了好的参考,FSO根本不能用于后期
绑定吗?
-
David W. Fenton http://www.dfenton .com /
usenet at dfenton dot com http ://www.dfenton.com/DFA/
这篇关于只有硬核GURUS - 早期与晚期绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!