J
Joshua K Briley
I just recently migrated from Access 2000 to 2003. It is being used as a
front end to SQL 2000. All of the "code" is in Access, where SQL is being
used as a dumping ground. In A2000, we wrote a routine that helped speed up
our searches (see below). However, this doesn't seem to be working well in
2003. I understand that they use different versions of VB. Any advice on
how to fix this problem? Thanks in advance.
Option Compare Database
'--------------------------------------
' Use DStart()instead of DFirst() to return
' the first sorted record in a domain.
'--------------------------------------
Function DStart(FieldName As String, DomainName As String, Optional _
Criteria As Variant)
Dim MyDB As Database, MySet As Recordset
' Error out if there is no fieldname sent.
If Len(FieldName) = 0 Then
MsgBox "You Must Specify a Field name", , "DStart"
Exit Function
End If
' Error out if there is no domain sent.
If Len(DomainName) = 0 Then
MsgBox "You Must Specify a Domain name", , "DStart"
Exit Function
End If
Set MyDB = CurrentDb()
Set MySet = MyDB.OpenRecordset(DomainName, dbOpenDynaset)
' Apply a filter to the recordset if a criteria is sent.
If Not IsMissing(Criteria) Then
MySet.Filter = Criteria
Set MySet = MySet.OpenRecordset()
End If
' If there are no records, return the null, else return the value
' of the first record.
If MySet.EOF Then
DStart = Null
Else
MySet.MoveFirst
DStart = MySet(FieldName)
End If
MySet.Close
MyDB.Close
End Function
'-------------------------------------------
'Use DEnd()instead of DLast() to return
' the last sorted record in a domain.
'-------------------------------------------
Function DEnd(FieldName As String, DomainName As String, Optional _
Criteria As Variant)
Dim MyDB As Database, MySet As Recordset
' Error out if there is no fieldname sent.
If Len(FieldName) = 0 Then
MsgBox "You Must Specify a Field name", , "DEnd"
Exit Function
End If
' Error out if there is no domainname sent.
If Len(DomainName) = 0 Then
MsgBox "You Must Specify a Domain name", , "DEnd"
Exit Function
End If
Set MyDB = CurrentDb()
Set MySet = MyDB.OpenRecordset(DomainName, dbOpenDynaset)
' Apply a filter to the recordset if a criteria is sent.
If Not IsMissing(Criteria) Then
MySet.Filter = Criteria
Set MySet = MySet.OpenRecordset()
End If
' If there are no records, return the null, else return the value
' of the last record.
If MySet.EOF Then
DEnd = Null
Else
MySet.MoveLast
DEnd = MySet(FieldName)
End If
MySet.Close
MyDB.Close
End Function
front end to SQL 2000. All of the "code" is in Access, where SQL is being
used as a dumping ground. In A2000, we wrote a routine that helped speed up
our searches (see below). However, this doesn't seem to be working well in
2003. I understand that they use different versions of VB. Any advice on
how to fix this problem? Thanks in advance.
Option Compare Database
'--------------------------------------
' Use DStart()instead of DFirst() to return
' the first sorted record in a domain.
'--------------------------------------
Function DStart(FieldName As String, DomainName As String, Optional _
Criteria As Variant)
Dim MyDB As Database, MySet As Recordset
' Error out if there is no fieldname sent.
If Len(FieldName) = 0 Then
MsgBox "You Must Specify a Field name", , "DStart"
Exit Function
End If
' Error out if there is no domain sent.
If Len(DomainName) = 0 Then
MsgBox "You Must Specify a Domain name", , "DStart"
Exit Function
End If
Set MyDB = CurrentDb()
Set MySet = MyDB.OpenRecordset(DomainName, dbOpenDynaset)
' Apply a filter to the recordset if a criteria is sent.
If Not IsMissing(Criteria) Then
MySet.Filter = Criteria
Set MySet = MySet.OpenRecordset()
End If
' If there are no records, return the null, else return the value
' of the first record.
If MySet.EOF Then
DStart = Null
Else
MySet.MoveFirst
DStart = MySet(FieldName)
End If
MySet.Close
MyDB.Close
End Function
'-------------------------------------------
'Use DEnd()instead of DLast() to return
' the last sorted record in a domain.
'-------------------------------------------
Function DEnd(FieldName As String, DomainName As String, Optional _
Criteria As Variant)
Dim MyDB As Database, MySet As Recordset
' Error out if there is no fieldname sent.
If Len(FieldName) = 0 Then
MsgBox "You Must Specify a Field name", , "DEnd"
Exit Function
End If
' Error out if there is no domainname sent.
If Len(DomainName) = 0 Then
MsgBox "You Must Specify a Domain name", , "DEnd"
Exit Function
End If
Set MyDB = CurrentDb()
Set MySet = MyDB.OpenRecordset(DomainName, dbOpenDynaset)
' Apply a filter to the recordset if a criteria is sent.
If Not IsMissing(Criteria) Then
MySet.Filter = Criteria
Set MySet = MySet.OpenRecordset()
End If
' If there are no records, return the null, else return the value
' of the last record.
If MySet.EOF Then
DEnd = Null
Else
MySet.MoveLast
DEnd = MySet(FieldName)
End If
MySet.Close
MyDB.Close
End Function