NauticalGent
Ignore List Poster Boy
- Local time
- Yesterday, 23:31
- Joined
- Apr 27, 2015
- Messages
- 6,337
Hello folks,
Seeking some advice/opinions. I have it in my head that TempVars are bad practice - not sure where it came from but the consensus here at AWF seems to be to avoid them.
My current job has be going over and documenting the existing App/Code. While doing so, I came accross this:
In the past I would achieve the same results with this:
And then enumerate them with:
My questions are: Do TempVars get a bad rep or should they be avoided? Is one method better than the other?
Seeking some advice/opinions. I have it in my head that TempVars are bad practice - not sure where it came from but the consensus here at AWF seems to be to avoid them.
My current job has be going over and documenting the existing App/Code. While doing so, I came accross this:
Code:
TempVars("EmployeeType") = rs!EmployeeType_ID.Value
TempVars("Identifier") = rs!Identifier.Value
TempVars("BuyerCode") = rs!BuyerCode.Value
TempVars("OfficeSymbol") = rs!OfficeSymbol.Value
TempVars("Name") = rs!Name.Value
In the past I would achieve the same results with this:
Code:
Public Type UserInfo
UName As String
EMail As String
JobTitle As String
LogDate As Date
End Type
Public uInfo As UserInfo 'Declare a GLOBAL Instance of the User Defined type
And then enumerate them with:
Code:
Dim MyDB As DAO.Database
Dim rst As DAO.Recordset
Set MyDB = CurrentDb
Set rst = MyDB.OpenRecordset("SELECT * FROM Employees WHERE [EmployeeID]=1", dbOpenSnapshot) '1 Record
'Fill the Enumeration/User Defined Type
With rst
uInfo.UName = ![LastName]
uInfo.EMail = ![email]
uInfo.JobTitle = ![Title]
uInfo.LogDate = ![HireDate]
End With
rst.Close
Set rst = Nothing
My questions are: Do TempVars get a bad rep or should they be avoided? Is one method better than the other?