Object Required Error

sktripuraneni
sktripuraneni used Ask the Experts™
on
my questions seems simple but im not able to figure out the error
here is how it goes
in my project form i have added a "image" control and dynamicaly im trying to change the dimensions of the image, that is im making it as an array using Redim, now when i trying to access the image array im getting the error object required

here is the code

If i <> 0 Then
    ReDim Img(i - 1)
    For j = 1 To i
        Load Img(j)
    Next j
    For j = 0 To i - 1
          Filename = mPath & flPictures.List(j)
          Img(j).Picture = LoadPicture(Filename)
    Next j
End If

im not getting any error while redim but the error is coming when im using it in the for loop that is "Load"
even if im commenting it im getting the error in the second for loop
i.e; Img(j).Picture = LoadPicture(Filename)
can anyone help me out
thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You need to add a SET

If i <> 0 Then
   ReDim Img(i - 1)
   For j = 1 To i
       Load Img(j)
   Next j
   For j = 0 To i - 1
         Filename = mPath & flPictures.List(j)
         SET mg(j).Picture = LoadPicture(Filename)
   Next j
End If
never mind on that last comment
If Img is your image control then you don't have to REDim it.  The following should work

If i <> 0 Then
   For j = 1 To i
       If Img.Ubound < i then
           Load Img(j)
       End If
       Img(j).Visible = true
       Img(j).Left = ???
       Img(j).Top = ???
   Next j
   For j = 0 To i - 1
         Filename = mPath & flPictures.List(j)
         Img(j).Picture = LoadPicture(Filename)
   Next j
End If


Loaded controls are loaded with the Width,Height,Left and Top of the 'Zero'(Img(0)) controls properties, they are also loaded with the visibility property set to false.

One thing to remember is that once a control is loaded it will Error if you try to reload it again.


There is no need to do Redim your controls. If the name  Img means a Image control with the index 0 in your form then you cannot even use a Redim. Do you have the code
"Option Explicit" at the beginning of the module.

If you donot have you won't get any problem in Redim statement. But you will get problem in loading as array.

Use Option Explicit in the beginning of the module.
Remove the Redim statment.

Load the controls in the array as you are doing now.
Make sure for the list name flPictures has enough file names in the list. IF you are not sure hard code the Filename.

Give a try. It will work.


..kannan


Author

Commented:
Yes it worked as said
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial