mlesniak001
MIS
Hi everyone,
Here is a confusing one:
I have a form, which is based (indirectly) on a crosstab query. This means that the resulting number of columns and thier names are different for each load of the form. I have worked thru almost all the issues of handling the dynamic columns (upto a limit). But now I am stuck on a problem with the OrderBy.
my basic process is:
- on load of the form:
-- get the current set of columns,
-- re-assign the data source to a set of column place holders
-- build a string with the desired OrderBy
-- set OrderByOn = true
- on close of the form:
-- set OrderByOn = False
-- set OrderBy = ""
The problem is that the value of SortBy is not being cleared, so that on the next load of the form, it is trying to use the last SortBy (often resulting in a error, when the column names happen to not be the same as last time).
Any ideas on why the VBA in Close is not working?
FYI, here is part of the code:
the funny thing is:
- if I remove the action Me.OrderByOn = True, then the value of OrderBy is properly set to "" in Close. but of course, the OrderBy then never occurs on the form...
any ideas on why OrderBy is being 'sticky'? By 'sticky', I mean that, when the form is opened in design view, the Order By value of the last run is still there, when it should be empty. agian, this does not happen when I do not set OrderByOn = True.
Here is a confusing one:
I have a form, which is based (indirectly) on a crosstab query. This means that the resulting number of columns and thier names are different for each load of the form. I have worked thru almost all the issues of handling the dynamic columns (upto a limit). But now I am stuck on a problem with the OrderBy.
my basic process is:
- on load of the form:
-- get the current set of columns,
-- re-assign the data source to a set of column place holders
-- build a string with the desired OrderBy
-- set OrderByOn = true
- on close of the form:
-- set OrderByOn = False
-- set OrderBy = ""
The problem is that the value of SortBy is not being cleared, so that on the next load of the form, it is trying to use the last SortBy (often resulting in a error, when the column names happen to not be the same as last time).
Any ideas on why the VBA in Close is not working?
FYI, here is part of the code:
Code:
Private Sub Form_Open(Cancel As Integer)
Dim intColCount As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim strName As String
Dim strSQL As String
Dim Length As Integer
Dim Position As Integer
Dim OK As String
Dim temp_order_by As String
temp_order_by = ""
Dim Exclude(1 To 2) As String
Exclude(1) = "SetID"
Exclude(2) = "Instance"
Dim db As Database
Dim rs As Recordset
Dim q1 As QueryDef
Set q1 = db.QueryDefs("q_set_instances_Crosstab")
q1.Parameters("_A_") = _A_ 'removed object names for brevity
Set rs = q1.OpenRecordset
intColCount = rs.Fields.Count
intControlCount = Me.Detail.Controls.Count
' Fill in information for the necessary controls.
k = 1
For i = 0 To intColCount - 1
'check if column should be excluded
OK = "Yes"
For j = LBound(Exclude) To UBound(Exclude)
If Exclude(j) = rs.Fields(i).Name Then
OK = "No"
End If
Next j
Debug.Print OK, rs.Fields(i).Name
If OK = "Yes" Then
strName = rs.Fields(i).Name
' MsgBox strName
Me.Controls("Dim" & k).ControlSource = strName
Me.Controls("Txt" & k).Caption = strName
Me.Controls("Dim" & k).ColumnHidden = False
If temp_order_by <> "" Then
temp_order_by = temp_order_by & ", " & Me.RecordSource & ".[" & strName & "]"
Else
temp_order_by = Me.RecordSource & ".[" & strName & "]"
End If
k = k + 1
End If
Next i
While k <= 8
Me.Controls("Dim" & k).ControlSource = ""
Me.Controls("Txt" & k).Caption = ""
Me.Controls("Dim" & k).ColumnHidden = True
k = k + 1
Wend
Debug.Print temp_order_by
Me.OrderBy = temp_order_by
Me.OrderByOn = True
End Sub
Private Sub Form_Close()
Me.OrderByOn = False
Me.OrderBy = ""
Debug.Print "cleared order_by"
Debug.Print Me.OrderBy, Me.OrderByOn
End Sub
the funny thing is:
- if I remove the action Me.OrderByOn = True, then the value of OrderBy is properly set to "" in Close. but of course, the OrderBy then never occurs on the form...
any ideas on why OrderBy is being 'sticky'? By 'sticky', I mean that, when the form is opened in design view, the Order By value of the last run is still there, when it should be empty. agian, this does not happen when I do not set OrderByOn = True.