godawgs85
07-18-2010, 07:26 PM
Hello All. Just joined the forum not long ago and am looking forward to the help. This is my first post.
I'm somewhat of a newbie to VBA and am learning as I go. I am working on developing an application for my company that involves data entry into a userform and then an analysis of that data.
Currently I have created a Class Module as I have heard Class modules are the best way to go to keep your codes clean and useful in other projects.
The current problem I am having now is translating properties that have been set up in the class module over to the userform.
I have the following code entered into my class module for a property displaying a buildings square footage:
Property Let BuildingRSF(newBuildingRSF As Long)
SFErrorMessage = "Please Enter a Valid SF."
If IsNumeric(newBuildingRSF) = True Then
p_BuildingRSF = newBuildingRSF
Else
MsgBox SFErrorMessage, vbOKOnly, "Square Footage Error"
End If
End Property
In translating this property over to the userform, I have the following code to set the input value as this property:
Private Sub BuildingRSF_AfterUpdate()
u_Lease.BuildingRSF = BuildingRSF
End Sub
I have already initialized the class (u_Lease) within the userform and as long as the value input into the BuildingRSF textbox is numeric the code works properly and the class property is defined. If a non numeric value is input, however, I get an error message.
My question is why is the error handling code that I defined in the class property not working? Is there a simple fix to this or do I need to handle the error in the userform? I'm hoping the former is the case otherwise my userform is going to have way too much code as I have a lot of these instances to handle.
Thanks in advance for any help that can be provided.
Also, what is the best resource to learn more about class modules and how they can be used in userforms, other modules, etc.?
Thanks!
I'm somewhat of a newbie to VBA and am learning as I go. I am working on developing an application for my company that involves data entry into a userform and then an analysis of that data.
Currently I have created a Class Module as I have heard Class modules are the best way to go to keep your codes clean and useful in other projects.
The current problem I am having now is translating properties that have been set up in the class module over to the userform.
I have the following code entered into my class module for a property displaying a buildings square footage:
Property Let BuildingRSF(newBuildingRSF As Long)
SFErrorMessage = "Please Enter a Valid SF."
If IsNumeric(newBuildingRSF) = True Then
p_BuildingRSF = newBuildingRSF
Else
MsgBox SFErrorMessage, vbOKOnly, "Square Footage Error"
End If
End Property
In translating this property over to the userform, I have the following code to set the input value as this property:
Private Sub BuildingRSF_AfterUpdate()
u_Lease.BuildingRSF = BuildingRSF
End Sub
I have already initialized the class (u_Lease) within the userform and as long as the value input into the BuildingRSF textbox is numeric the code works properly and the class property is defined. If a non numeric value is input, however, I get an error message.
My question is why is the error handling code that I defined in the class property not working? Is there a simple fix to this or do I need to handle the error in the userform? I'm hoping the former is the case otherwise my userform is going to have way too much code as I have a lot of these instances to handle.
Thanks in advance for any help that can be provided.
Also, what is the best resource to learn more about class modules and how they can be used in userforms, other modules, etc.?
Thanks!