0

我正在尝试为我的项目修改 Roggers 的示例,浏览 MS Access 表单中的多个图像。

但是,我想知道如何为图像控件添加单击事件以打开详细信息表单。

表单背后的代码如下:

    Private Sub P_FillControls()
On Error GoTo ErrTrap

    Dim Cnt As Long

    Cnt = 1
    Do Until (Cnt > BlockSize Or rst.EOF)
        P_SetValues Cnt

        Cnt = Cnt + 1
        rst.MoveNext
    Loop

    If Cnt <= BlockSize Then
        For Cnt = Cnt To BlockSize
            P_SetNulls Cnt
        Next
    End If

ExitPoint:
    On Error GoTo 0
    Exit Sub

ErrTrap:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitPoint
End Sub

Private Sub P_SetValues(Cnt As Long)
On Error GoTo ErrTrap

    If RecCount > 0 Then
        Me("Rn_" & Format(Cnt, "00")).Caption = (rst.AbsolutePosition + 1)
    Else
        Me("Rn_" & Format(Cnt, "00")).Caption = ""
    End If

    Me("Lb_" & Format(Cnt, "00")).Caption = Nz(rst.Fields("ImageName"), "")
    Me("Im_" & Format(Cnt, "00")).Picture = Nz(rst.Fields("ImageFile"), "")
    Me("ID_" & Format(Cnt, "00")) = rst.Fields("ImageFile")

    ' Note - For no caption, dot is used in lieu of
    '            zero length string, so as to prevent the
    '            label from disappearing

ExitPoint:
    On Error GoTo 0
    Exit Sub

ErrTrap:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitPoint
End Sub

Private Sub P_SetNulls(Cnt As Long)
On Error GoTo ErrTrap

    Me("Rn_" & Format(Cnt, "00")).Caption = "."
    Me("Lb_" & Format(Cnt, "00")).Caption = "."
    Me("Im_" & Format(Cnt, "00")).Picture = "."
    Me("ID_" & Format(Cnt, "00")) = Null

    ' Note - For no caption, dot is used in lieu of
    '            zero length string, so as to prevent the
    '            label from disappearing

ExitPoint:
    On Error GoTo 0
    Exit Sub

ErrTrap:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitPoint
End Sub

Public Sub P_Initialize()
    On Error Resume Next

    RecCount = 0    ' Default
    Me.LbNoImage.Visible = False

    ' Remove any existing instance of the recordset
    If Not rst Is Nothing Then
        rst.Close
        Set rst = Nothing
    End If

    ' This recordset will finally get closed in form's
    ' close event.

    Set rst = CurrentDb.OpenRecordset("Q_ImageNormalSort")
   ' Set rst = CurrentDb.OpenRecordset("Q_Dynamic_Query")

    If rst.EOF And rst.BOF Then
        ' There are no records
        P_FillControls
        Me.LbNoImage.Visible = True
        P_SetStatusNavBtns
        Me.CmdAdd.SetFocus
        Exit Sub
    End If

    rst.MoveLast
    RecCount = rst.RecordCount
    LastID = rst.Fields("ImageFile")
    rst.MoveFirst
    FirstID = rst.Fields("ImageFile")

    ' First Load (signified by step size argument = 0)
    P_Next 0

    Me.LbRecMsg.Caption = "Of  " & RecCount

    On Error GoTo 0
End Sub

在示例中,“Im_”是在窗体上保存图像的控件。

我会感谢你的帮助。

约瑟夫

4

1 回答 1

0

将以下 Sub 放在代码底部的某个位置:

Function OpenMyForm(strFormName As String)
    DoCmd.OpenForm strFormName
End Function

将其粘贴在您设置图像的下面的代码中:

Me("Im_" & Format(Cnt, "00")).OnClick = "=OpenMyForm('F_Details')"
于 2013-09-12T18:24:34.297 回答