这似乎是一件简单的事情,我相信我之前已经这样做了,但是我已经有一段时间了,因为我在Access中做了任何UI编程。我需要做的是在表单上放一个按钮,在子表单的数据表和表单视图之间切换。
我找到了一个defaultview属性,但看起来没什么可以在窗体已经打开后切换窗体的视图。
基本上我需要我可以填写以下代码的属性..
sfEmployeeBatchEntry.Form.??? = acFormDS
答案 0 :(得分:8)
我自己找到了它。我错过了它,因为它使用了愚蠢而笨重的RunCommand语法,而不是控件或表单类上的简单属性或方法。
这不是很漂亮,但对后人来说,这就是答案。
'You have to set focus to the subform control or the change view call will'
'fail (UGH!)'
MyForm.mySubFormControl.SetFocus
'Change to datasheet view...'
DoCmd.RunCommand acCmdSubformDatasheet
'Change to Form View...'
DoCmd.RunCommand acCmdSubformFormView
答案 1 :(得分:0)
我尝试了在不同网站上找到的许多不同的解决方案。有些似乎不必要地复杂化。我清理了一些混乱,发现这最符合我的需求。
Dim intView As Integer
intView = Me.Form.CurrentView
If intView = 1 Then
DoCmd.RunCommand (acCmdSubformDatasheetView)
Else
DoCmd.RunCommand (acCmdSubformFormView)
End If
Exit Sub
答案 2 :(得分:0)
要在“连续”和“数据表”之间切换子窗体的视图,请使用以下代码:
Private Sub cmdToggleView_Click()
If Me.frmViewDetailedTransactionsSub.Form.CurrentView = 1 Then
Me.frmViewDetailedTransactionsSub.SetFocus
DoCmd.RunCommand acCmdSubformDatasheetView
Exit Sub
End If
If Me.frmViewDetailedTransactionsSub.Form.CurrentView = 2 Then
Me.frmViewDetailedTransactionsSub.SetFocus
DoCmd.RunCommand acCmdSubformFormView
Exit Sub
End If
End Sub