VB6Generate Valid Employee ID Values
Option Explicit

Public Function GetEmp_ID() As String
   Dim TempEmp_ID As String

   Randomize Timer

   ' generate a new employee ID
   TempEmp_ID = Left(rsEmployee("fName"), 1)
   If Len(rsEmployee("minit")) = 0 Then
      TempEmp_ID = TempEmp_ID & "-"
   Else
      TempEmp_ID = TempEmp_ID & _ 
         Left(rsEmployee("minit"), 1)
   End If
   TempEmp_ID = TempEmp_ID & _      
      Left(rsEmployee("minit"), 1)
   TempEmp_ID = TempEmp_ID & Int(Rnd(1) * 1000 + 10000)
   TempEmp_ID = TempEmp_ID & "F"

   GetEmp_ID = UCase(TempEmp_ID)
End Function

Listing 2 Using a public function within the data environment lets you collect database-related code in one place, and access it as data environment methods.