使用文件夹中的文件填充列表框 - 文件路径位于表单上的备注字段中 [英] populate a list box with the files in a folder - filepath is in memo field on form
本文介绍了使用文件夹中的文件填充列表框 - 文件路径位于表单上的备注字段中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好;
我被困了,想解决我的问题。
使用Access 2003
- 我的表单在备忘录字段中有文件路径。
- 我有一个文件路径文件夹中文件列表的列表框
- 当我移动到记录时,我希望列表框从文件路径中填充文件夹中的最新文件。表单
- 有时没有文件路径或无效文件路径,因此如果没有文件路径则需要忽略,如果字段中有无效的文件列表文本则需要消息
推荐答案
这里是一个名为lstFilesInDirectory的ListBox和一个包含文件路径的文本框的一般概念命名为txtFilePath:
here is the general idea for a ListBox named lstFilesInDirectory and a Text Box containing the File Path named txtFilePath:
展开 | 选择 | Wrap | 行号
这太奇怪了,我尝试了很多方法但它不起作用。我是否必须对列表框属性执行一些特殊操作?或是私人子不正确。如果我在RowSource中引用存储的查询但是没有从代码中获取信息,则列表框有效。
Private Sub Form_Activate()
Dim lst作为ListBox
Dim txt As TextBox
Dim strFileName As String
Dim strPath As String
设置lst = Me![lstFilesInDirectory]
设置txt = Me![txtFilePath ]
''确保txtFilePath中有东西
如果IsNull(txt)则退出Sub
''确保PATH存在,它实际上是一个文件夹
如果dir
It is so weird, I have tried many approaches and it does not work. Do I have to do something special with the list box properties? or is the Private Sub incorrect. The list box works if i reference a stored query in the RowSource, but does not get the info from the code.
Private Sub Form_Activate()
Dim lst As ListBox
Dim txt As TextBox
Dim strFileName As String
Dim strPath As String
Set lst = Me![lstFilesInDirectory]
Set txt = Me![txtFilePath]
''Make sure there is something in txtFilePath
If IsNull(txt) Then Exit Sub
''Make sure that the PATH exists, and it is in fact a Folder
If dir
(txt,vbDirectory)=""然后
MsgBox" The Folder" &安培; txt& "不存在!",vbExclamation,"找不到文件夹>
退出Sub
结束如果
strPath = txt
''如果我们到这里,我们有一个有效的文件夹。如有必要,添加''\''
如果正确
(txt, vbDirectory) = "" Then
MsgBox "The Folder " & txt & " does not exist!", vbExclamation, "Folder Not Found"
Exit Sub
End If
strPath = txt
''If we get here, we have a valid Folder. Add a ''\'' if necessary
If Right
这篇关于使用文件夹中的文件填充列表框 - 文件路径位于表单上的备注字段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文