Solved

How do I move focus to an Image object

Posted on 2010-11-29
11
780 Views
Last Modified: 2013-11-29
I've been strugling with this problem for two days now:
I've got a form with about 100 Image objects and 100 textbox objects.
I would like to perform several actions on the objects, but instead of making a list in Visual Basic like:

Set ctl = image1
Set ctl = image2
Set ctl = image3

and so on I would like to make this dynamic like: Set ctl = "image" & me.imagenumber, but I haven't been able to get this to work.
I've also tried to do this with:

DoCmd.GoToControl ("Input" & Me.imagenumber)       for the textbox object
DoCmd.GoToControl ("Image" & Me.imagenumber)      for the image object

The strange thing is that for the textbox object it works perfectly, but when I try the same thing for the image object I get:
"Run-time error 2110 - access can't move the focus to the control"

It's probably (hopefully?) pretty easy to solve, but so far I haven't been able to find a solution and it's getting pretty frustrating.
Any help will be very much appreciated.

Kind regards,

Joris

0
Comment
Question by:Athoss22
  • 5
  • 4
  • 2
11 Comments
 
LVL 8

Expert Comment

by:Emil_Gray
ID: 34235401
An image cannot receive focus. Sorry 'bout that.
0
 

Author Comment

by:Athoss22
ID: 34235411
Ok thanks for the information, but  maybe there's another way around my problem?
The reason I'm is asking because I need to change (amongst other things) the postion of the images. So instead of making lists like:

Me.image1.Top = Me.Top
Me.image1.Left = Me.Left
Me.image2.Top = Me.Top
Me.image2.Left = Me.Left
Me.image3.Top = Me.Top
Me.image3.Left = Me.Left

and so on, I hope there's a better way to do this. Do you know if it's possible to do something like:
"Me.image" & me.imagenumber & ".Top" = Me.Top

Any suggestions?

Kind regards,

Joris
0
 
LVL 8

Expert Comment

by:Emil_Gray
ID: 34235415
Oh, you might try putting your images in bound or unbound frames which can receive focus.
0
 
LVL 8

Expert Comment

by:Emil_Gray
ID: 34235439
Check out this information. It might help you.

http://www.alvechurchdata.co.uk/company/useimage.html
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34235679
You can set the focus to a Image control using.

I will confess that I am a bit hazy as to what you ultimate goal is here.

You cannot set a Textbox equal to an image control.

If your goal here is to set the "Control source" of the textbox to the "Picture" property of the Image contol, then try something like this:

Dim ctl As Control
Dim intDesig As Integer
Dim strMatch As String
    For Each ctl In Me.Section(0).Controls
        If ctl.ControlType = acTextBox Then
            intDesig = CLng(Right(ctl.Name, Len(ctl.Name) - 3))
            strMatch = "img" & intDesig
            ctl = Me.Controls(strMatch).Picture
        End If
    Next ctl

Sample attached


JeffCoachman


Access-EEQ26646024buildControlNa.mdb
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 8

Expert Comment

by:Emil_Gray
ID: 34235754
Jeff, does your code actually set focus on the image? I always was under the impression that could not be done. You cannot tab to an image since there is no tab stop. Same thing with a label. If his images are placed in frames then there is a tab stop and the frame can receive focus.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34236199
My code simply sets the control source of the textbox to the corresponding image .Picture property.

I am still not quite sure of what the asker is looking for, so this is just my interpretation...

I am even more confused by http:#a34235411
Now the goal is to set the position of the controls?
I am just not understanding the reason or need for doing this.

Perhaps I am just missing something simple...

Let's see if Athoss22 will take a step back and clearly explain what the ultimate goal is here...

Jeff
0
 
LVL 8

Expert Comment

by:Emil_Gray
ID: 34236287
Jeff, sounds like the best thing. I am curious what it might be. Guessing that it might be he wants to cause the images to move around on the form. I hope he's got a lot of ram and a fast processor if so.
0
 

Author Comment

by:Athoss22
ID: 34237411
Thanks for all the feedback. To clarify what I'm trying to achieve I attached a screenshot. As you can see I have several rows of images of products of different sizes. Underneath each image there's a textbox to enter an amount of the product.
It's no problem to generate this layout from data in a table, but I need the form to get flexible.
If one of the products gets replaced by another product I need to adjust the size and the image of the image control and the size of the textbox below the image. Furthermore I need to adjust the location of all the products/textboxes to the right of the product that has changed.
If for example product 3 on row 2 gets replaced by a smaller product I need to adjust position of all the products in row 2 to the right of product 3 so that they move to the left.

I thought it would be easiest if I could set focus to the images and textboxes that need to be adjusted, but since that's not possible I'm looking for another way to do this.
Layout.jpg
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 34238916
1. Well, what you are presenting above now is a far cry from what you originally requested
In the future simply state your ultimate goal.
When you tell us "How" you want things done (move focus to an Image object)
It hamstrings us.
What you are requesting has nothing to do moving the focus to an image control.
;-)


2. As far as I can tell, you need to "Group" these controls
(What version of Access are you using?, as the steps are different for different Access versions)

Open the form in design view and select the two controls (The image and the textbox) that you want to Group.
(Click the first control, then hold down the shift key and select the other contol)
Then (In Access 2007) click: Arrange-->Control Layout-->Then click the "Group" icon.
Now when you click on either control, they will both be selected (Grouped)
If you resize or move one, the other will follow.
(in Access 2003, click format-->Group.)

In Access 2007 You can even create a "Layout".
This is where you select "All" the contols and click the "Tabular" control Layout.
This will resize all the controls, in the "Grid" stlye you are asking about.

You can probably play around with both of these options (possibly in conjuction with one another) to get what you are after.

3. I also will say that this is a layout style that I have never seen. (not even in a web page)
Are you sure this is the only way that this data can be displayed?
This will require a fair amount of maintenance everytime a product changes.
As far as I can tell, this will never be truely "Dynamic" (Automatically adjusting on the fly) as you are are specifying.
Also, what if you have a thin product image with a long price? (price may not fit in the skinny textbox.)


JeffCoachman
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34254319
;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now