英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论