【发布时间】:2012-03-28 20:15:45
【问题描述】:
我有一个访问报告,它根据从目录中获取图像的表更新 4 个图像控件。该报告为每条记录生成一个页面,但是图像控件在第 1 页之后没有更改(仅显示所有其他页面的相同图像)。显然,该代码在 Windows XP 上运行良好,但现在在 Windows 7 操作系统(均使用 Office 07)上无法运行。代码如下:
Private Sub Report_Current()
UpdateImages
End Sub
Private Sub Report_Load()
UpdateImages
End Sub
Private Sub Report_Page()
UpdateImages
End Sub
Private Sub UpdateImages()
On Error GoTo errHandler
Dim RS As DAO.Recordset
Set RS = CurrentDb.OpenRecordset("SELECT Image_Loc, Image_Name FROM HH_Media WHERE InspectionID = " & CInt(Me.InspectionID.Value) & " ORDER BY MediaID ASC")
If Not RS.BOF And Not RS.EOF Then
Dim i As Integer
For i = 1 To 4
If Not RS.EOF Then
Dim pictureCtrl As Image
Set pictureCtrl = GetControl("Image" & i)
Dim strImage As String
strImage = RS.Fields("Image_Loc").Value & "\" & RS.Fields("Image_Name").Value
If Not pictureCtrl Is Nothing Then
If FileExists(strImage) Then
pictureCtrl.Picture = strImage
SetLabel "lblImage" & i, RS.Fields("Image_Name").Value
Else
pictureCtrl.Picture = ""
SetLabel "lblImage" & i, "Does not exist"
End If
End If
RS.MoveNext
Else
Exit For
End If
Next
End If
RS.Close
Set RS = Nothing
Exit Sub
errHandler:
MsgBox "An error occurred while updating the form display." & vbNewLine & Err.Description, vbApplicationModal + vbCritical + vbDefaultButton1 + vbOKOnly, Me.Name
Resume Next
End Sub
图像确实存在于表中引用的目录中。关于缺少什么的任何想法?
谢谢
【问题讨论】:
-
我不知道,但似乎微软在新版本中随机删除了各种 API 功能。当我从 Access 2000 更新到 2007 时,由于 FileDialog 和 RecordSet.RecordCount 不再存在,导致许多功能被破坏。
-
您确定在第 1 页之后调用了 UpdateImages - 有时页面事件不会触发...
-
@DJ.,似乎它只点击了 UpdateImage 程序 4 次。如何让每页触发事件?
标签: ms-access vba dao recordset