重新加载Access表单中的表单,使用一个按钮。

huangapple go评论63阅读模式
英文:

reload the form with a button in access forms

问题

我有一个访问表单(仅编辑表单)。它有一个OnLoad事件,将仅显示一个组合框供用户选择,然后通过AfterUpdate事件,将显示表单中的一些控件,通过控件的可见和启用属性。然后用户可以点击一个按钮来保存这段代码中的脏记录:

If Me.Dirty Then
    Me.Dirty = False
End If

到此为止一切正常。

我需要的是在同一个按钮点击事件中,使表单重新加载到其原始状态,即重新加载表单,就像之前的OnLoad事件一样,只显示我的组合框

我尝试了requery和refresh方法,但这并不能让我回到OnLoad事件的状态。

英文:

I have an access form (edit only form). It has an OnLoad event that will show only a combobox for the user to choose from, which then by an AfterUpdate event will show some controls in the form, through visible and enable properties of the controls. Then the user can click a button to save the dirty record by this code:

    If Me.Dirty Then
          Me.Dirty = False
    End If

Till here everything is ok.

What I need is with the same button click event, the form to reload to its original status, i.e. to reload the form as if it is closed and re-opened like the previous OnLoad event to show only my combobox

I tried the requery and refresh methods, but that does not bring me back to the OnLoad event shape.

答案1

得分: 3

尝试通过将逻辑放入单独的子程序中来抽象您的代码。

而不是:

Sub MyCombo_AfterUpdate()
    Me!foo.Visible = True
    Me!bar.Enabled = True
    ' etc.
End Sub

创建一个这样的子程序:

Sub ShowEditControls(bShow As Boolean)
    Me!foo.Visible = bShow 
    Me!bar.Enabled = bShow 
    ' etc.
End Sub

然后简单地:

Sub MyCombo_AfterUpdate()
    ShowEditControls True
End Sub

Sub btSave_Click()
    If Me.Dirty Then
          Me.Dirty = False
    End If

    Me!MyCombo.SetFocus
    Me!MyCombo.Value = Null   ' or whatever initial value you need

    ShowEditControls False
End Sub
英文:

Try to abstract your code by putting logic into a separate sub.

Instead of

Sub MyCombo_AfterUpdate()
    Me!foo.Visible = True
    Me!bar.Enabled = True
    ' etc.
End Sub

create a sub for this:

Sub ShowEditControls(bShow As Boolean)
    Me!foo.Visible = bShow 
    Me!bar.Enabled = bShow 
    ' etc.
End Sub

and then simply

Sub MyCombo_AfterUpdate()
    ShowEditControls True
End Sub

and

Sub btSave_Click()
    If Me.Dirty Then
          Me.Dirty = False
    End If

    Me!MyCombo.SetFocus
    Me!MyCombo.Value = Null   ' or whatever initial value you need

    ShowEditControls False
End Sub

huangapple
  • 本文由 发表于 2023年4月17日 03:21:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76029894.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定