stalakos
10-24-2002, 05:01 AM
Hi,
I have got these two functions...
Private Function ABCScore(bytAttNum As Byte, strField As String) As Single
Dim rst As ADODB.Recordset
Dim strsql As String
strsql = " SELECT tblAttributeIntervals.[" & strField & "] " _
& " FROM tblAttributeIntervals " _
& " WHERE (((tblAttributeIntervals.Attribute) = " & bytAttNum & "));"
Set rst = OpenADORecordSet(strsql)
ABCScore = rst(strABC)
rst.Close
End Function
Private Function GetFieldName(bytAttNum As Byte, strField) As String
Dim rst As ADODB.Recordset
Dim strsql As String
strsql = " SELECT tblAttributes.[" & strField & "] " _
& " FROM tblAttributes " _
& " WHERE (((tblAttributes.AttributeNo)=" & bytAttNum & "));"
Set rst = OpenADORecordSet(strsql)
GetFieldName = rst(strField)
rst.Close
End Function
that both use another function:
Private Function OpenADORecordSet(strsql As String) As ADODB.Recordset
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.Open strsql
Set OpenADORecordSet = rst
End Function
Now the top two Functions essentially do the same thing, expect they return a different type of data back.
Would it be better to combine the two into something like this:
Private Function ValueFromRecordset(strsql As String, strField As String) As Variant
Dim rs As ADODB.Recordset
Set rs = OpenADORecordSet(strsql)
ValueFromRecordset = rs(strField)
rs.Close
End Function
where I use the Variant variable to make it more generic.
really my question is:
Will my code be quicker with one function using the Variant or with two functions using a specific variable type?
or is it six of one and half of the other??
I have got these two functions...
Private Function ABCScore(bytAttNum As Byte, strField As String) As Single
Dim rst As ADODB.Recordset
Dim strsql As String
strsql = " SELECT tblAttributeIntervals.[" & strField & "] " _
& " FROM tblAttributeIntervals " _
& " WHERE (((tblAttributeIntervals.Attribute) = " & bytAttNum & "));"
Set rst = OpenADORecordSet(strsql)
ABCScore = rst(strABC)
rst.Close
End Function
Private Function GetFieldName(bytAttNum As Byte, strField) As String
Dim rst As ADODB.Recordset
Dim strsql As String
strsql = " SELECT tblAttributes.[" & strField & "] " _
& " FROM tblAttributes " _
& " WHERE (((tblAttributes.AttributeNo)=" & bytAttNum & "));"
Set rst = OpenADORecordSet(strsql)
GetFieldName = rst(strField)
rst.Close
End Function
that both use another function:
Private Function OpenADORecordSet(strsql As String) As ADODB.Recordset
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.Open strsql
Set OpenADORecordSet = rst
End Function
Now the top two Functions essentially do the same thing, expect they return a different type of data back.
Would it be better to combine the two into something like this:
Private Function ValueFromRecordset(strsql As String, strField As String) As Variant
Dim rs As ADODB.Recordset
Set rs = OpenADORecordSet(strsql)
ValueFromRecordset = rs(strField)
rs.Close
End Function
where I use the Variant variable to make it more generic.
really my question is:
Will my code be quicker with one function using the Variant or with two functions using a specific variable type?
or is it six of one and half of the other??