访问子形式可见性



我有一个访问表单,其中包含从表中填充的表单名称的下拉列表。当某人从下拉菜单中选择特定项目时,我希望能够显示1个相应的子形式。例如,我在下拉列表中有表格1,表格2,表格3。我选择表格2,并出现两个子形式。我尝试访问VBA中可见的属性属性,但遇到了多个错误,但从未奏效。谁能帮忙?

这是填充下拉的代码:

Private Sub Form_Load()
Dim dba As Database
Dim rst As Recordset
Dim SQL As String
Set dba = CurrentDb
Set rst = dba.OpenRecordset("tbl_Forms", dbOpenDynaset, dbSeeChanges)
SQL = "SELECT ListName FROM tbl_Forms"
Set rst = dba.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges)
Set rst = Nothing
Set dba = Nothing
End Sub

对于我尝试的子形式可见性:

forms!mainform.Form1.visbile = false 
forms!mainform.Form2.visbile = false
forms!mainform.Form3.visbile = false
Select case dropdown
case 1 
forms!mainform.Form1.visbile = true 
forms!mainform.Form2.visbile = false
forms!mainform.Form3.visbile = false
case 2
forms!mainform.Form1.visbile = false
forms!mainform.Form2.visbile = true
forms!mainform.Form3.visbile = false
case 3 
forms!mainform.Form1.visbile = false
forms!mainform.Form2.visbile = false
forms!mainform.Form3.visbile = true
end select 

这是原始的,但是应该为您提供一个开始。您可以使用所需子图的字符串名称设置子形式容器的源对象。完成此操作后,您可以抓取对MS Access定义的基本表格类的引用,并使用其中定义的属性和方法。

,如果您愿意,您也可以获取对特定表格的引用,尽管这变得更加复杂。

从这里开始,您将需要进行一些游戏才能使它以自己想要的方式行事。

Option Compare Database
Option Explicit
Private currentSubformReference As Form

Private Sub cboSubForms_AfterUpdate()
    LoadSubform (cboSubForms)
    currentSubformReference.DividingLines = False
    currentSubformReference.ControlBox = False
    '  . . . Etc
End Sub

Private Sub LoadSubform(ByVal SubformName As String)
    'Set the SourceObject property of the subform/subreport
    ' container object on your form:
    Me.sfmContainer.SourceObject = SubformName
    ' Grab a reference to the Form that is used as the
    ' SourceObject (this will only get you access to the
    ' properties exposed by the MS Access Form Class):
    Set currentSubformReference = Me.sfmContainer.Form
End Sub

在下拉中写下三个值为form1,form2,form3(或任何表格名称),然后代码:

forms!mainform.Form1.visbile = false 
forms!mainform.Form2.visbile = false
forms!mainform.Form3.visbile = false
With Me.    
Select case Me.DropDownName.Value
case "Form1" 
 With Me.MainFormName.Form
 .Form1.visbile = true 
 .Form2.visbile = false
 .Form3.visbile = false
 End With 
case "Form2" 
 With Me.MainFormName.Form
 .Form1.visbile = false 
 .Form2.visbile = true
 .Form3.visbile = false
 End With
  case "Form3" 
 With Me.MainFormName.Form
 .Form1.visbile = false 
 .Form2.visbile = false
 .Form3.visbile = true
 End With
  End Select  
  End With 

相关内容

  • 没有找到相关文章

最新更新