访问模块中的报告复选框(ms访问)

时间:2012-03-22 13:17:55

标签: ms-access

我正在尝试将模块写入数据库,但我需要从报表中访问复选框值。如何访问模块中的表单内容? (我正在使用access 2007)

以下是报告的onclick事件中的代码,其中包含复选框,但我需要运行一个宏,它在同一个onclick事件中执行不同的操作,所以我希望在该宏中使用runco​​de调用模块。

    Private Sub Command9_Click()
       Dim query As String
       Dim qdfNew As QueryDef
       Dim dbLib As Database
       Set dbLib = CurrentDb()




        If Me.ReferenceCheck.Value = True Then
           query1 = " Record_Num, [Report_Num], [Title], [Report_Date], [Author], [Organization], [Test Org], [Test Name], [Test Date], [POC]"


        Else
           query1 = ""
        End If

       If Me.SoilCheck.Value = True Then
           query2 = "[Soil Condition],[Soil_C_Method], [Soil Compaction Method],[Custom Soil Compaction Method], [General Soil Classification], [Water Content Expedient], [Dry Density Expedient], [LL]"


        Else
           query2 = ""

       End If

   queryHead = "SELECT "
   queryTail = " FROM searchR"

   finalQuery = queryHead
   If Me.ReferenceCheck.Value = True Then
      finalQuery = finalQuery & query1

   End If

   If Me.SoilCheck.Value = True Then
      If finalQuery = "SELECT " Then
          finalQuery = finalQuery & query2
      Else
          finalQuery = finalQuery & ", " & query2

      End If

   End If    

       If (finalQuery = "SELECT ") Then
             finalQuery = "SELECT * FROM searchR"
       Else
             finalQuery = finalQuery & queryTail
       End If


       dbLib.QueryDefs.Delete "filterQuery"
       Set qdfNew = dbLib.CreateQueryDef("filterQuery", finalQuery)
       Child0.Form.RecordSource = "filterQuery"


    End Sub

1 个答案:

答案 0 :(得分:1)

您可以在代码中运行宏

DoCmd.RunMacro "myMacro"

我想知道为什么你会遇到删除和创建查询def的麻烦。在第一个实例中,您可以修改那里的那个,但更简单地只是将SQL指定为记录源。

Child0.Form.Recordsource = finalQuery