如何在访问中隐藏和取消隐藏文本框

时间:2017-01-06 08:10:58

标签: forms access-vba ms-access-2010

如何在访问vba中隐藏和取消隐藏文本框,但在转到下一条记录时不会更改。请帮帮我

我试过这段代码:

Private Sub cboserdos_AfterUpdate()
If cboserdos.Value = "Lulus Sertifikasi" Then
            Me.txt1.Visible = False
            Me.lbl1.Visible = False
            Me.txt2.Visible = False
            Me.lbl2.Visible = False
            Me.txt3.Visible = False
            Me.lbl3.Visible = False
            Me.txt4.Visible = False
            Me.lbl4.Visible = False
            Me.Frameserdos.Visible = False
            Me.Label824.Visible = False
 Else
            Me.txt1.Visible = True
            Me.lbl1.Visible = True
            Me.txt2.Visible = True
            Me.lbl2.Visible = True
            Me.txt3.Visible = True
            Me.lbl3.Visible = True
            Me.txt4.Visible = True
            Me.lbl4.Visible = True
            Me.Frameserdos.Visible = True
            Me.Label824.Visible = True

 End If

If cboserdos.Value = "Belum Sertifikasi" Then
             Me.txt1.Visible = False
            Me.lbl1.Visible = False
            Me.txt2.Visible = False
            Me.lbl2.Visible = False
            Me.txt3.Visible = False
            Me.lbl3.Visible = False
            Me.txt4.Visible = False
            Me.lbl4.Visible = False
            Me.Frameserdos.Visible = False
            Me.Label824.Visible = False
 Else
            Me.txt1.Visible = True
            Me.lbl1.Visible = True
            Me.txt2.Visible = True
            Me.lbl2.Visible = True
            Me.txt3.Visible = True
            Me.lbl3.Visible = True
            Me.txt4.Visible = True
            Me.lbl4.Visible = True
            Me.Frameserdos.Visible = True
            Me.Label824.Visible = True
 End If

End Sub

问题是当我点击下一条记录时,文本框更改中有不同的数据。

1 个答案:

答案 0 :(得分:1)

使用 OnCurrent 事件 - 并将代码剪切四分之一:

Private Sub Form_Current()

    Dim Visible As Boolean

    Select cboserdos.Value 
        Case "Lulus Sertifikasi", "Belum Sertifikasi"
            Visible = False
        Case Else
            Visible = True
    End Select

    Me.txt1.Visible = Visible 
    Me.lbl1.Visible = Visible 
    Me.txt2.Visible = Visible 
    Me.lbl2.Visible = Visible 
    Me.txt3.Visible = Visible 
    Me.lbl3.Visible = Visible 
    Me.txt4.Visible = Visible 
    Me.lbl4.Visible = Visible 
    Me.Frameserdos.Visible =Visible 
    Me.Label824.Visible = Visible 

End If