Calculations slowing forms down - SQL server backend

G

Gabby Girl

Good morning!

We have recently switched our back end to SQL server and since then any of
our search forms with calculations have slowed right down. I would like to
remove any calcuations when the form opens and add a command button that does
the calculations once the user has selected all of his criteria. Following
is the function used for the search forms.

Start of code:
************************************************************

Function FormFilterForm(strForm As String, strSubForm As String, strTag As
String, strTbl As String, strSortOrder As String, tfClear As Boolean,
tfCalendar As Boolean) As Integer
'************************************************************
'Description - to filter form while form is open
'
'Requires
' strForm - Calling Form
' strSubForm - (Optional) Sub Form
' strTag - Value of control Tag to identify the controls to be
used in filter
' strTbl - Name of table
' strSortOrder - the sql Sort Order to be used (Excludes Order by,
Example Tbl.Field1, Tbl.Field2)
' tfClear - True to clear filter
' tfCalendar - True to open a calendar to perform filtering
'
'Returns
' True if everything is OK
' False if there was a problem
'
'How to use
' varRetVal = FormFilterForm(name, "","FilterTag", "Tbl", "" &
txtSortOrder, False, False)
' varRetVal = FormFilterForm(Parent.name, name,"FilterTag", "Tbl", "" &
txtSortOrder, False, False)
'
'Instructions on how to set up
' Create an invisible Sort Order Control
'
' Duplicate all of the controls to be used in filter
' Remove the Control Source and rename these controls the
txtControlSource. Example City becomes txtCity
' Set the Tag property on all of these filter controls
' If the control is not a text field then Field Type is required.
' Field Type is set up by appending the following Field Type to the tag
seperated with a ;
'
' Field Type
' 1 - Yes/No, 2 - Byte , 3 - Integer , 4 - Long, 5 -
Currency, 6 - Single
' 7 - Double, 8 - Date/Time, 10 - Text , 12 - Memo
' Example FilterTag;7 or FilterTag;8
'
'Revision History -
' John Ewing Jan 5, 2000 Created.
'
'************************************************************
Dim ctrl As Control
Dim frm As Form
Dim intFldType As Integer
Dim intSep As Integer
Dim strCtrl As String
Dim strCtrlTag As String
Dim strFld As String
Dim strOrderBy As String
Dim strSql As String
Dim strWhere As String
Dim tfFilter As Boolean
Dim varRetval As Variant

On Error GoTo FormFilterFormError

FormFilterForm = False

Set frm = Forms(strForm)

If tfCalendar Then varRetval = CalendarOpen(True)

strWhere = ""
strOrderBy = ""

If Len(strSubForm) = 0 Then
For Each ctrl In frm.Controls
If Len("" & ctrl.Tag) > 0 Then
strCtrlTag = ctrl.Tag
intFldType = dbText
tfFilter = False

If strCtrlTag = strTag Then
tfFilter = True
Else
If InStr(1, strCtrlTag, ";") > 0 Then
intSep = InStr(1, strCtrlTag, ";")
If Left(strCtrlTag, intSep - 1) = strTag Then
tfFilter = True
intFldType = Val("" & mid(strCtrlTag, intSep + 1))
End If
End If
End If

If tfFilter Then
If tfClear Then
ctrl.Value = Null
Else
strCtrl = mid(ctrl.Name, 4)
strWhere = FilterSetWhere(strWhere, strTbl, strCtrl,
intFldType, frm(ctrl.Name))
End If
End If
End If
Next ctrl
Else
For Each ctrl In frm(strSubForm).Form.Controls
If Len("" & ctrl.Tag) > 0 Then
strCtrlTag = ctrl.Tag
intFldType = dbText
tfFilter = False

If strCtrlTag = strTag Then
tfFilter = True
Else
If InStr(1, strCtrlTag, ";") > 0 Then
intSep = InStr(1, strCtrlTag, ";")
If Left(strCtrlTag, intSep - 1) = strTag Then
tfFilter = True
intFldType = Val("" & mid(strCtrlTag, intSep + 1))
End If
End If
End If

If tfFilter Then
If tfClear Then
ctrl.Value = Null
Else
strCtrl = mid(ctrl.Name, 4)
strWhere = FilterSetWhere(strWhere, strTbl, strCtrl,
intFldType, frm(strSubForm).Form(ctrl.Name))
End If
End If
End If
Next ctrl
End If

If Len(strSortOrder) > 0 Then strOrderBy = "ORDER BY " & strSortOrder

strSql = "SELECT [" & strTbl & "].* "
strSql = strSql & "FROM [" & strTbl & "] "
If Len(strWhere) > 0 Then strSql = strSql & "Where (" & strWhere & ")"
If Len(strOrderBy) > 0 Then strSql = strSql & strOrderBy
strSql = strSql & ";"

If Len(strSubForm) = 0 Then
frm.RecordSource = strSql
Else
frm(strSubForm).Form.RecordSource = strSql
End If

FormFilterForm = True

Exit Function
'************************************************************
FormFilterFormError:
Select Case Err
Case Else: varRetval = errormsg("FormFilterForm", Err, Error)
End Select
Exit Function

End Function

************************************************************

Can anyone guide me in the right direction?

Any advice/direction in greatly appreciated.
Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top