User Defined Types (UDTs) are a convenient way to store related data in one variable. They are essentially data types that you (as the programmer) setup. You could, of course, store unrelated data in UDTs, but that’s not generally how they’re used.
I find them most useful when I have to pass information between procedures. Rather than have, say, four parameters in a procedure, I prefer to use a UDT with four elements. That way, I can pass one variable. For me, it makes the code more readable and self-documenting. And you get the benefit of Intellisense when using UDTs, which is nice.
Here’s a simple, contrived example of how to use a UDT. The Type statement is used to define the UDT and must be outside of any procedures.
Private Type Applicant
FirstName As String
LastName As String
ResumeRecd As Boolean
InterviewDate As Date
Dim uApp As Applicant
uApp.FirstName = “Dick”
uApp.LastName = “Kusleika”
uApp.ResumeRecd = True
uApp.InterviewDate = #7/15/2004#
Sub UseUDT(uInput As Applicant)
If uInput.InterviewDate = Date Then
Debug.Print uInput.FirstName, uInput.LastName