DAO访问记录集没有更新
问题描述:
我有一个访问报告,它根据从目录中获取图像的表更新4个图像控件。该报告会为每条记录生成一个页面,但是图像控件在页面1后不会改变(仅显示所有其他页面的相同图像)。公正地说,代码在Windows XP上运行良好,现在不能在Windows 7操作系统上运行(都使用Office 07)。以下是代码:DAO访问记录集没有更新
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
图像确实存在于表中引用的目录中。任何想法缺少什么?
谢谢
答
每当我需要做一些动态内容,我总是用[段] _format事件 - 所以,如果你的控制都在细节部分则:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If FormatCount = 1 then 'only need to do this once per record
UpdateImages
Endif
End Sub
答
我从来看到getControl方法访问,我没有很多的使用图像控制的经验,但似乎是Dim语句应该读起来更像:
Dim pictureCtrl as Control
Set pictureCtrl = Me.Controls("Image" & i)
我会插入一个断裂d验证
strImage = RS.Fields("Image_Loc").Value & "\" & RS.Fields("Image_Name").Value
正在返回您期望的值。您也可以缩短这些到:
strImage = rs!Image_Loc & "\" & rs!Image_Name
有时访问不喜欢加“.value的”,因为这已经是默认的回报。
我不知道,但它似乎像微软随机删除新版本中的各种API功能。当我从Access 2000更新到2007年时,由于FileDialog和RecordSet.RecordCount不再存在,一些功能被破坏。 – McGarnagle 2012-03-28 20:20:13
是否确定UpdateImages在页面1之后被调用 - 有时页面事件不会触发... – 2012-03-28 20:27:39
@DJ。,好像它只是触发UpdateImage过程4次。我如何使每页的事件触发? – artwork21 2012-03-28 20:30:55