我有一个子表单数据表,它的RecordSource可以是可变的。我的数据库基于用户选择构建一个SQL查询(每个查询包含不同的列集合)。生成的查询将是子窗体上数据表的RecordSource。(用户只读视图)
问题:
各种查询在单独运行时都会产生所需的结果。
将结果查询设置为数据表的RecordSource不会产生任何结果(没有列/行)
我怀疑我需要将查询的属性插入到子表单中,以便看到任何结果(就像菜单条中的“添加现有字段”一样)。
问题:
有什么建议可以让我从第一步开始吗?
谢谢!
发布于 2017-11-02 16:46:05
从子窗体对象中删除数据表窗体,并将源对象属性保留为空。创建一个新查询(sql并不重要),并将其命名为qryTemp (或任何您喜欢的)。然后,每当您想为子窗体设置源时,请使用以下命令
CurrentDb.QueryDefs("qryTemp").SQL = "<your new sql here>"
<yoursubformobject>.SourceObject = "Query.qryTemp".
发布于 2017-11-02 15:59:33
下面是一个用于填充子表单的示例:
Private Sub cmdFind_DisplayName_Click()
Dim dbs As Database, rstPatient As Recordset
Dim txtDisplayName, strQuote As String
strQuote = Chr$(34)
On Error GoTo ErrorHandler
Me.OrderBy = "DISPLAYNAME"
Me.OrderByOn = True
Set dbs = CurrentDb
Set rstPatient = Me.RecordsetClone
txtDisplayName = Trim(InputBox("Please Enter Patient Name ", "Patient Find By Name"))
txtDisplayName = UCase(txtDisplayName) & "*"
If IsNull(txtDisplayName) Then
MsgBox ("No Patient Name Entered - Please Enter a Valid Patient Name")
Else
rstPatient.FindFirst "[DISPLAYNAME] Like " & strQuote & txtDisplayName & strQuote
If Not (rstPatient.NoMatch) Then
Me.Bookmark = rstPatient.Bookmark
Me.Refresh
Else
MsgBox ("Patient Not Found - Please Enter a New Patient Name")
End If
End If
GoTo Exit_cmdFind_Click
ErrorHandler:
MsgBox LTrim(RTrim(Me.NAME)) + "." + "Patient Find By Display Name - " + "Error: " + AccessError(Err.Number)
Exit_cmdFind_Click:
rstPatient.Close
Set dbs = Nothing
Set rstPatient = Nothing
End Sub
https://stackoverflow.com/questions/47085832
复制相似问题