
Wanted: JPEG picture viewer VBX
Quote:
> I am trying to do something that maybee shouldn't be done. I have
> many objects on my form that correspond to fields in an Access DB.
> Prior to saving I check for NULL in the field and set it to " " if it
> is NULL. Rather than do an If Then for every object, I want to put them
> inside a FOR NEXT loop because the objects names end in a digit, IE:
> Q1, Q2, Q3 etc. The delima is: How do you reference the contents of a
> variable as being an object? The following is what I want to do, but
> obviously the sintax is wrong. What is the correct (if any) way to do
> this?
> Dim oTemp 'Temporary variable to hold name of object on form
> Dim fTemp 'Temporary variable to hold name of database field
> Dim X 'for the FOR NEXT LOOP
> FOR X = 1 to 8
> oTemp = "Q" & X
> fTemp = "FieldName" & X
> IF oTemp.TEXT = "" THEN
> oTemp.TEXT = " "
> END IF
> DataBase.Fields(fTemp) = oTemp.TEXT
> NEXT
> Any help would be appreciated. Replies can be sent via EMail.
> Thanks!
> Jim Hunter
Hi Jim,
It is possible, but in a slightly different way.
Set your text boxes as a control array.
Example:
Rename Q1 as Q and give it an index of 1
Rename Q2 as Q and give it an index of 2
Doing that, you will be asked if you want to create a control array:
say Yes
Then proceed with the others, following the example above. You won't
be asked anymore if you want to create a control array.
Then your existing code can be used with minor modifications.
FOR X = 1 to 8
fTemp = "FieldName" & X
IF Q(X).TEXT = "" THEN
Q(X).TEXT = " "
END IF
DataBase.Fields(fTemp) = Q(X).TEXT
NEXT
You had the right idea, it just needed some slight modifications.
Another piece of advice:
Are you doing this to avoid an "Invalid use of Null" error?
another way to avoid that, (faster since you avoid the above loop)
would be to do this where you access the data from your database
Q(X) = "" & Database("FieldName" & X)
Good luck
Duane