I have a form with about 15 fields, we'll call them Field1,Field2, etc. With the exception of the primary key, all the fields can be null.
I have a type defined, we'll call it a FormStruct, with all it's elements equivelant to the form fields and all are variant types to allow nulls.
i.e.
On a control's AfterUpdate event a variety of tests are done based on control's input.
i.e.
Each function assigns values to FormStruct.fieldX based on a query or some other function and returns a boolean depending on if the query was successful.
The problem occurs upon reaching the updateform: part and some of the values in formstruct aren't defined depending on which function was or wasn't run. So when I try to assign me.fieldX to formstruct.fieldX I get a zero legth string, or a mismatch error.
How do I get unassigned properties of formstruct to be set to null without too much extra code?
Is there a way to iterate through all the values in formstruct? that way I could make my code a bit shorter.
I'm no VBA pro, but I'm open minded.
I have a type defined, we'll call it a FormStruct, with all it's elements equivelant to the form fields and all are variant types to allow nulls.
i.e.
Code:
Type FormStruct
Field1 as variant
Field2 as varient
'etc.
end Type
On a control's AfterUpdate event a variety of tests are done based on control's input.
i.e.
Code:
sub control_afterupdate()
if function1(formstruct) then
goto updateform
elseif function2(formstruct) then
goto updateform
elseif function3(formstruct) then
goto updateform
else
exit sub
end if
updateform:
me.field1 = formstruct.field1
me.field2 = formstruct.field2
me.field3 = formstruct.field3
'etc.
end sub
Each function assigns values to FormStruct.fieldX based on a query or some other function and returns a boolean depending on if the query was successful.
The problem occurs upon reaching the updateform: part and some of the values in formstruct aren't defined depending on which function was or wasn't run. So when I try to assign me.fieldX to formstruct.fieldX I get a zero legth string, or a mismatch error.
How do I get unassigned properties of formstruct to be set to null without too much extra code?
Is there a way to iterate through all the values in formstruct? that way I could make my code a bit shorter.
I'm no VBA pro, but I'm open minded.