在vba中设置文件名的路径

时间:2012-08-10 23:10:12

标签: vba ms-access-2007

希望这是有道理的,有人可以指出我正确的方向。我正在Access 2007中构建一个项目

我有一个带有文本字段PhotoName的表tblEmployees,带有Listbox List0的表单Form2和空的Image Boxes Image1和Image2

Field PhotoName存储照片的名称,即122000_998.jpg没有完整路径,例如C:\照片\ 122000_998.jpg

List0有4列数据,列(4)是Photo文件名的位置,即122000_998.jpg

我需要在Form2打开时自动从多行中选择一张照片

我可以使用以下内容从任何行检索照片以显示在Image1和Image2中,但前提是我将tblEmployees PhotoNamI中的文件名从122000_998.jpg更改为C:\ Photos \ 122000_998.jpg 或者如果我将Me.Image1.Picture = Me.List0.Column(4)更改为Me.Image1.Picture =“C:\ VisitorImage \”& Me.List0.Column(4)

Me.List0.Selected(0)= True

Me.Image1.Picture = Me.List0.Column(4)

Me.List0.Selected(1)= True

Me.Image2.Picture = Me.List0.Column(4)

如何在上面运行Form Open事件过程时添加上面的路径来查找照片,而不添加tblEmployees PhotoName的路径或将其添加到每行代码。我问道,路径可能会改变,只是改变路径值而不是通过每行来更容易,因为可能有20多张照片

所有帮助表示感谢,谢谢

Jedski3

1 个答案:

答案 0 :(得分:1)

怎么样?

dim pathprefix as String
pathprefix = "C:\Photos\"
Me.List0.Selected(0) =True
Me.Image1.Picture = pathprefix + Me.List0.Column(4)
Me.List0.Selected(1) =True
Me.Image2.Picture = pathprefix + Me.List0.Column(4)