By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,072 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,072 IT Pros & Developers. It's quick & easy.

Multi-select images for report - create array?

tuxalot
100+
P: 200
I have 10 unbound image controls on a form and below each I have a bound radio button. On my report, I have 5 unbound image controls. The user selects multiple images on the form with a maximum of 5 selections. Let's assume the radio buttons representing the image controls on the form are named 1-10. Let's also assume the image controls on the report are named A, B, C, D, E. In all cases, image control A on the report will contain image 1 and image control B will contain image 2. For C, D and E they would display the remaining selected images from the form. How these images are ordered is not important. How can I dynamically assign the remaining selected images to image controls C, D and E on the report?
Nov 19 '11 #1
Share this Question
Share on Google+
16 Replies


NeoPa
Expert Mod 15k+
P: 31,709
Your radio buttons are bound it seems, but you don't tell us what they're bound to. It seems a fair assumption that this must be irrelevant. None of the image controls is bound. This may be Access, but you've clearly decided not to use anything to do with a database in this question. That leaves you with standard program logic.

Process through the form to determine which images are required and set those, with your code, into the available image controls on the report. It's very non-standard, but it matches the question in that respect.
Nov 19 '11 #2

tuxalot
100+
P: 200
The radio buttons are bound to 10 fields in a table with paths to external images (the image above the radio button in each case). The images are simply on the form to give the user a reference to what they are selecting. I do not understand how I can make image control "C" on my report show, at times, image 3 and other times show image 6.
Nov 19 '11 #3

NeoPa
Expert Mod 15k+
P: 31,709
Tuxalot:
The radio buttons are bound to 10 fields in a table with paths to external images (the image above the radio button in each case).
This doesn't make sense, and it really needs to. What type of text field can be bound to a RadioButton control?

The rest of it I got, but without knowing your actual position better I cannot advise correctly.

If we're dealing with records in a table then the approach is totally different from what you described initially (assuming your design even supports it at all).
Nov 19 '11 #4

tuxalot
100+
P: 200
Let me step out and get above the situation and perhaps I can do a better job at describing my needs.

In simplified terms, I have 10 images on a form of which only five can be selected. I want to present the five selected items from these ten on a report.
Nov 19 '11 #5

NeoPa
Expert Mod 15k+
P: 31,709
Tuxalot:
Let me step out and get above the situation and perhaps I can do a better job at describing my needs.
Sounds like a good idea. Let me know when you've done so.

I hope your second sentence wasn't supposed to be it as that was less helpful even than your first attempt (and completely ignores what I've said so far). I'm sure it wasn't and I can wait for you to be ready.
Nov 19 '11 #6

tuxalot
100+
P: 200
Honestly NeoPa I thought the second sentence would help you understand. I am not looking for code as much as direction on what options are possible. I suppose where I am getting hung up is how to allow an image control in a report to derive it's data from more than one source (ex. imgC in the report might show data from selections 3-10 in the form).

Perhaps I put 10 image controls on the report to match the 10 on the form, and collapse them if they do not have data so I can present the 5 remaining in a row. Would this be a good approach?
Nov 19 '11 #7

NeoPa
Expert Mod 15k+
P: 31,709
No Tux. It doesn't make sense. I suspect this is because your understanding of what is stored where is somewhat lacking (I'm guessing here but it sounds that way to me). You need to understand that the report cannot access the data on the form directly, as the data is not stored on the form, but in a table that the form is bound to. That means that you need to specify some logic that enables you to see the same data on your report. This normally works by specifying a filter. So far though, you have provided no relevant information that anyone else could use to determine how to prepare any such filter. And that only describes one way that we may need to approach it. We don't even know enough from you to determine if this makes sense or if an entirely different approach is required.
Nov 19 '11 #8

ADezii
Expert 5K+
P: 8,679
I do know what you are trying to accomplish, but I agree with NeoPa in that your methodology is not sound. The concept, as I see it, is roughly this:
  1. Loop through all the Controls on you Form.
  2. If the Control is a Radio Button, increment a Counter.
  3. If the Control is a Radio Button and is selected, increment a second, selected Counter.
  4. Make some kind of provision if the number of Selected Radio Buttons is > 5.
  5. Create a Public Array with the Absolute PATHs to the Selected Images (you indicate some kind of Pointer to this).
  6. Populate the Array.
  7. In the Open() Event of your Report, set the Picture Property of the 5 Image Controls (Image1...Image5) to the Values (PATHs) stored in the Array.
  8. This has all been tested, and works quite well.
    Expand|Select|Wrap|Line Numbers
    1. Dim ctl As Control
    2. Dim bytNumSelected As Byte
    3. Dim bytOptButton As Byte
    4.  
    5.  
    6. For Each ctl In Me.Controls
    7.   With ctl
    8.     If .ControlType = acOptionButton Then
    9.        bytOptButton = bytOptButton + 1
    10.          If .Value Then
    11.            bytNumSelected = bytNumSelected + 1
    12.              If bytNumSelected > 5 Then
    13.                MsgBox "You can only select a MAXIMUM of 5 Images"
    14.                'RESET The Radios Buttons, Clear the Array
    15.                  Exit Sub
    16.              Else
    17.                'Populate with PATHs for Test Purposes
    18.                astrImages(bytNumSelected) = "C:\Stuff\EMPID" & _
    19.                                             CStr(bytOptButton) & ".bmp"
    20.              End If
    21.       End If
    22.     End If
    23.   End With
    24. Next 
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Report_Open(Cancel As Integer)
    2. Dim bytCtr As Byte
    3.  
    4. For bytCtr = 1 To 5
    5.   Me.Controls("Image" & CStr(bytCtr)).Picture = astrImages(bytCtr)
    6. Next
    7. End Sub
P.S. Make some provisions for Erasing the Array at certain points in the Code.
Nov 19 '11 #9

tuxalot
100+
P: 200
the report cannot access the data on the form directly
Understood.

Taking another tact.

Let's assume I have 10 columns named i1 - i10. The URL to an external image is shown in row 1 in the example below. Like this:

i1 i2 i3 i4 i5 i6 i7 i8 i9 i10
url1 url2 url3 url10

I want the data in columns i1-i10 where the URL is not null to show up as images on my report in a linear fashion (i.e. this example would be one row of 4 images, equally spaced, etc.)
Nov 19 '11 #10

tuxalot
100+
P: 200
Thanks for the reply ADezii. I can tell that one should only post on this board if they have well thought out ideas, and possibly some code, whether working or not. Flawed methodology? Probably. A more accurate statement might be the lack of any methodology at all.

I actually thought my original question was simple and easily understood. I have 10 images on a form. A user can select any combination of images, with #1 & #2 being required, and the selected 5 would appear on a report. That's it.

I will give your solution a go and I thank you for your effort in putting that together.
Nov 19 '11 #11

ADezii
Expert 5K+
P: 8,679
Public Arrays can be a little tricky, so don't forget to Erase the Array at critical points, such as: the Close() Event of the Report, if > 5 Radio Buttons Selected along with the the resetting of these Buttons to False, etc. This is easily done via:
Expand|Select|Wrap|Line Numbers
  1. Erase astrImages
Nov 19 '11 #12

NeoPa
Expert Mod 15k+
P: 31,709
It's not that the approach indicated by ADezii won't work. It's that it may not be an appropriate solution for this problem. As we don't know the problem clearly enough. If the data is bound data then this approach is inappropriate. I was leading you to that understanding (or trying).
Nov 20 '11 #13

tuxalot
100+
P: 200
NeoPa and Adezii,

Thank you both for sticking with me, and pointing out flaws in my logic where appropriate. I truly appreciate your help. This is certainly an education. I have thought a bit more about this and I think some background might help clarify what I am trying to accomplish.

The db I am working on deals with machinery maintenance. The machinery has a set of maintenance procedures that are developed in the db. Various pieces of equipment are necessary to perform the maintenance. While developing the procedures, a user is presented with a set of pictures showing the types of equipment that might be necessary to perform the required maintenance. Not all pieces of equipment are used for every procedure. The user then selects the picture if that equipment is applicable to the maintenance operation.

Selecting the picture triggers a bound textbox below each picture to display the URL of an external image of the selected equipment. The textboxes are bound to my main table in columns E1 - E10. So the resulting columns might look like this:

Expand|Select|Wrap|Line Numbers
  1.  E1   E2   E3   E4   E5   E6   E7   E8   E9   E10
  2. urlE1     urlE3     urlE5     urlE7          urlE10     
  3.  
So up to this point all is working. I need help with the reporting.

My report is based on a query of the main table. I would like to have image controls on the report show the selected images in a single row, equally spaced. Below each picture will be a label with a description of the selected equipment and I suppose I can add an additional 10 bound fields in my table to capture those data.

I hope this better describes my needs. I realize your time is valuable and better spent helping folks with focused questions so I apologize for taking up your time previously.

Tux.
Nov 23 '11 #14

NeoPa
Expert Mod 15k+
P: 31,709
That's a good job Tux. I'm sorry to say though, that this indicates a setup which seems so unnatural to me that I find I can't work within it without wanting to strip everything out and start again from scratch. I've spent a lot of time trying to find a way that I can help but everything I can think of turns out to be insupportable due to the structure of the design you have.

My instinct would be to design something that could be reported without the need to have the form open first (ADezii's quite clever solution uses information from the form to print the correct pictures onto the report).

If you want to design a report that can work generally from the data you have available then, yes - you've guessed it, you need to focus your thinking on the data you have available. Notice you haven't really presented the data structure yet. I suggest it's too late for that in this thread, but if you do take that course and get stuck, that's what you need to focus on and that's what you need to include in your question.

Best of luck.

PS. As your question stands, ADezii's post (#9) does answer it. It's not a solution I'd be too happy with myself, but that's down to the question rather than the answer.
Nov 23 '11 #15

tuxalot
100+
P: 200
I'm sorry to say though, that this indicates a setup which seems so unnatural to me that I find I can't work within it without wanting to strip everything out and start again from scratch
The structure can certainly be modified. How would you do it?

My instinct would be to design something that could be reported without the need to have the form open first
The report uses a query as it's recordsource and the data (URL's) are stored in the table. The form does not need to be open for reporting.

As your question stands, ADezii's post (#9) does answer it.
You mentioned that if the data was bound, ADezii's solution may not be appropriate. As I mentioned in the last post, the data is bound.
Nov 23 '11 #16

NeoPa
Expert Mod 15k+
P: 31,709
I've replied via PM as most of what I say is not really related to the question.
Nov 23 '11 #17

Post your reply

Sign in to post your reply or Sign up for a free account.