查询def更新时表单不刷新

时间:2017-04-19 15:56:34

标签: ms-access access-vba

我有一个包含子窗体的表单,该子窗体显示查询的数据表视图。主窗体上有一个按钮,单击该按钮将修改查询的SQL。单击该按钮时,将按预期修改查询,但除非我关闭并重新打开主窗体,否则结果不会在子窗体中更新。

我试图重新查询子表单和主表单。我试图刷新子表单和主表单。我已经尝试了两者的各种组合,但除了关闭和重新打开主窗体外,什么都不会更新子窗体中显示的数据。

有任何见解或建议吗?

这是我在主窗体中的代码,它在单击按钮时运行。

    Dim f as Form
    Set f = Me.frm_Subform.Form

    ' Update the query def
    Dim sSQL As String
    Dim sqlArray As Variant
    sSQL = CurrentDb.QueryDefs("myQuery").SQL
    sqlArray = Split(sSQL, "ORDER BY")
    sSQL = Left(sqlArray(0), Len(sqlArray(0)) - 3)
    sSQL = sSQL & " AND (STAFF.FULLNAME <> 'JOHN DOE') "
    sSQL = sSQL & "ORDER BY" & sqlArray(1)
    CurrentDb.QueryDefs("myQuery").SQL = sSQL

    ' Refresh the subform
    F.Requery
    Me.Requery
    F.Refresh
    Me.Refresh
    F.Repaint
    Me.Repaint

1 个答案:

答案 0 :(得分:1)

为什么修改查询?只是为了改变排序顺序?为数据表视图构建表单集,并使用DoCmd.SetOrderBy或

将排序条件应用于OrderBy属性
var A = [5,2,4,7,1,3,2,6];      

mergeSort(A);

function mergeSort(array) {
  if (array.length < 2) {
    return array;
  }
  var midpoint = parseInt(array.length/2);
  var left = array.slice(0, midpoint);
  var right = array.slice(midpoint, array.length);
  alert("Calling merge with arrays, " + left + " and " + right);
  return merge(mergeSort(left), mergeSort(right));
}

function merge(L, R) {
  var Output = []; // Output array is clearly defined here.

  var m = 0;
  var n = 0;

  while(m < L.length && n < R.length)
  {
    for (var x = 0; x < Math.min(L.length, R.length); x++) {
      if (L[m] <= R[n]) {
        Output.push(L[m]); // Does not work! 
        m++;        
        alert("Output from merge is array " + toString(Output)); 
        // Alerts: Output from merge is array [object Undefined]
      } else {
        Output.push(R[n]); // Does not work!
        n++;
        alert("Output from merge is array " + toString(Output));
        // Alerts: Output from merge is array [object Undefined]
      }             
    }
  }         

  // Check if either L or R have an element left
  if (m < L.length) {
    for (var o = m; o < L.length; o++) {                    
      Output.push(L[o]);
    }               
  }
  if (n < R.length) {
    for (var o = n; o < R.length; o++) {
      Output.push(R[o]);
    }               
  }
  return Output;                    
}

如果您想动态应用过滤条件,请使用类似于OrderBy的代码。