刷新查询数据的表单

时间:2014-12-25 07:45:06

标签: sql access-vba

我遇到的问题是,它的记录源是基于包含三个连接表的查询。我正在尝试创建一个切换类型开关,它更新其中一个底层表格中的字段,随后需要在表单上显示。问题是该字段保持空白,并且不会在表单上更新,直到其他记录经过相同的过程。问题似乎与刷新或重新查询有关。下面是我的代码,其中基础表中的字段在最后一个SQL更新语句中更新。

Private Sub cmdFlowType_Click()

Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb

Dim strSql As String

    strSql = "Select * from tblDependencies02 "
    Set rs = db.OpenRecordset(strSql, dbOpenDynaset)
    rs.MoveLast

If IsNull(Me.txtFlow) Then

    txtFlow = 1

End If

If txtFlow < rs.RecordCount Then
    txtFlow = txtFlow + 1

Else
    txtFlow = 1

End If

strSql = "UPDATE tblDependencies01 INNER JOIN tblDependencies02 ON tblDependencies01.Flow = tblDependencies02.[No] SET tblDependencies01.FlowDescription = [tblDependencies02].[Type]"
Application.DoCmd.RunSQL (strSql)

Me.Refresh

End Sub

1 个答案:

答案 0 :(得分:0)

我找到了。在SQL更新之前添加一个简单的requery

Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb

Dim strSql As String

    strSql = "Select * from tblDependencies02 "
     Set rs = db.OpenRecordset(strSql, dbOpenDynaset)
     rs.MoveLast


If IsNull(Me.txtFlow) Then

    txtFlow = 1

End If


If txtFlow < rs.RecordCount Then
    txtFlow = txtFlow + 1

Else
    txtFlow = 1

End If

Me.Requery


strSql = "UPDATE tblDependencies01 INNER JOIN tblDependencies02 ON tblDependencies01.Flow = tblDependencies02.[No] SET tblDependencies01.FlowDescription = [tblDependencies02].[Type]"
Application.DoCmd.RunSQL (strSql)

Me.txtFlowType.Requery