MS Access / VBA代码:如何组合这两个程序

时间:2013-05-07 22:31:51

标签: vba access-vba

我是一个VBA新手试图将这两个子程序合并到一个程序中 - 任何人都可以提供如何做到这一点吗?

基本上,我试图将图像添加到Access报告中(在第二个代码块中 - 它正在检查/创建图像路径) - 其中已经检查了其他信息。数据库产品记录。

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Dim x$, y$, i%

x = ""
For i = 1 To 10
    y = Me("txtOp" & i) & ""
    If y > "" Then
        If x > "" Then x = x & "  "
        x = x & "Option " & i & ": " & y
    End If
Next
If x > "" Then x = CR & x
Me.txtProduct = Me.txtItem & "" & x

If Me.Adjustment Then
    Me.txtShowSKU = ""
Else
    Me.txtShowSKU = Me.txtSKU
End If



Dim x, y, OK%
OK = False
x = Me.txtImage & ""
If x > "" Then
    y = getparm("ImagePath")
    If y > "" Then
        If Right$(y, 1) <> "\" Then y = y & "\"
        If Left$(x, 1) = "\" And Len(x) > 1 Then x = Mid$(x, 2)
        If FileExists(y & x) Then OK = True: x = y & x
    End If

    If OK Then
        Me.imgProd.visible = True
        Me.imgProd.Picture = x
    Else
        Me.imgProd.visible = False
    End If
End If

End Sub

1 个答案:

答案 0 :(得分:1)

我认为这应该有效:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    Dim x as String
    Dim y as String
    Dim i as Integer

    For i = 1 To 10
        y = Me("txtOp" & i) & ""
        If y > "" Then
            If x > "" Then x = x & "  "
            x = x & "Option " & i & ": " & y
        End If
    Next
    If x > "" Then x = CR & x
    Me.txtProduct = Me.txtItem & "" & x

    If Me.Adjustment Then
        Me.txtShowSKU = ""
    Else
        Me.txtShowSKU = Me.txtSKU
    End If

    Dim OK as Boolean
    y = ""

    x = Me.txtImage & ""
    If x > "" Then
        y = getparm("ImagePath")
        If y > "" Then
            If Right$(y, 1) <> "\" Then y = y & "\"
            If Left$(x, 1) = "\" And Len(x) > 1 Then x = Mid$(x, 2)
            If FileExists(y & x) Then OK = True: x = y & x
        End If

        If OK Then
            Me.imgProd.visible = True
            Me.imgProd.Picture = x
        Else
            Me.imgProd.visible = False
        End If
    End If

End Sub