Results 1 to 13 of 13
  1. #1
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150

    Active Control on Image


    Hello,

    I am trying to obtain certain properties of images once clicked, so that I can enlarge the image size and change the location of one when it's clicked. I'm hoping to restore the image size and its original image when clicked again. However, I cannot seem to be able to get the properties correctly. Below is a sample code I used just to test if I can obtain the properties.
    Code:
    Private Sub ImgFrontElevation_Click()
    
    
    Dim ctlCurrentControl As Control
    Dim CurrentControlName As String
    Dim strCurrentSize As String
    
    
    
    
    Set ctlCurrentControl = Screen.ActiveControl
    CurrentControlName = ctlCurrentControl.Name
    
    
    MsgBox (CurrentControlName)
    End Sub
    Whenever I click on the image, I get the name of a text box that has focus. What am I doing wrong?

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,399
    activecontrol is the control that has the focus

    previouscontrol is the one that had the focus before - less useful because the user may have clicked on a non image control

    if you are talking about width and height you need the control.width and control.height properties which are singles and expressed in twips (1440 twips=1", 567 twips = 1cm) even if the properties show inches or cm.

    you either need to put the code into the image click event or make it a public function and call it from the click event. If the former, then you would refer to the image directly and if the latter, activecontrol would work

  3. #3
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150
    Quote Originally Posted by Ajax View Post
    activecontrol is the control that has the focus

    previouscontrol is the one that had the focus before - less useful because the user may have clicked on a non image control

    if you are talking about width and height you need the control.width and control.height properties which are singles and expressed in twips (1440 twips=1", 567 twips = 1cm) even if the properties show inches or cm.

    you either need to put the code into the image click event or make it a public function and call it from the click event. If the former, then you would refer to the image directly and if the latter, activecontrol would work
    Thanks Ajax for your reply. I thought I had replied, but I do not see it in the thread, so I shall reply again. I am putting the code into the image click event. However, my issue now is that when I click on the image, I am getting the property of another control (text box). I am not certain why it is not recognizing the image as the active control. Would you happen to know why that is?

  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,399
    No, but if the event is the event image - why are you not just using that image control properties? Or if you are using another sub/function, just pass the control as a parameter?

  5. #5
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150
    I'm not quite following you. I am using the click event of the image control. When I click on it, I want to change its properties such as enlarge the size and location. I also want to capture its original properties so that I can restore its original size and location. I hope I am making sense.

  6. #6
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,399
    if your image control is called image1 then you would have

    Code:
    Private Sub image1_click()
    
        image1.height=2000
        image1.width=2000
    
    End Sub
    to capture the old values you would need a public variable in the form declared at the top of the module below option explicit e.g.

    Code:
    public oldheight as single
    public oldwidth as single
    and modify your click event to something like

    Code:
    Private Sub image1_click()
    
        if image1.height=2000 then ' image already enlarged so revert to old size
            image1.height=oldheight
            image1.width=oldwidth
        else 'image not enlarged so enlarge it
            oldheight=image1.height
            oldwidth=image1.width
            image1.height=2000
            image1.width=2000
        end if
    
    End Sub

  7. #7
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150
    I see how your code may work. Since I have four different images on the form, that's why I was hoping to use the active control method to capture its name, size, and location, so that I don't have to code for each image.

  8. #8
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150
    and since they all have different positions, that's why I want to capture each image's properties when clicked.

  9. #9
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,399
    OK then do this


    put this in a module

    Code:
    Public oldCtrl as control
    
    Public Sub changeImage(ctrl as control)
    
        if ctrl.height=2000 then ' image already enlarged so revert to old size
            ctrl.height=oldctrl.height
            ctrl.width=oldctrl.width
        else 'image not enlarged so enlarge it
            oldctrl=ctrl
            ctrl.height=2000
            ctrl.width=2000
        end if
    
    End Sub
    and in your form
    Private Sub image1_click()

    changeImage image1

    End Sub

  10. #10
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150
    When the code gets to
    oldCtrl = ctrl
    , I get "Object variable or With block variable not set" error.

  11. #11
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150
    When I hover over oldCtrl, it says oldCtrl = Nothing.

  12. #12
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,399
    try

    set oldctrl=ctrl

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    EDIT: BTW the phone rang and I didn't finish my thought before posting the below example. I was thinking about a loop in the form and passing info to a procedure. The code below is not complete, either.

    I was just dealing with this in a function thing earlier today. Try passing the form name and control name to the function.

    Code:
    Public Sub changeImage(FormName As String, ControlName As String)
    Dim ctrl As Control
    Dim frm As Form
    
    Set frm = Application.Forms(FormName)
    ctrl = frm.Controls(ControlName)
    
        If ctrl.Height = 2000 Then ' image already enlarged so revert to old size
            ctrl.Height = oldctrl.Height
            ctrl.Width = oldctrl.Width
        Else 'image not enlarged so enlarge it
            oldctrl = ctrl
            ctrl.Height = 2000
            ctrl.Width = 2000
        End If
    
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 12
    Last Post: 10-01-2014, 08:17 PM
  2. Active X control comes grayed out
    By jj1 in forum Access
    Replies: 1
    Last Post: 05-29-2014, 09:13 AM
  3. Replies: 1
    Last Post: 05-22-2013, 02:34 PM
  4. Active X - Web Browser control doesn't work
    By forstatd in forum Reports
    Replies: 1
    Last Post: 06-02-2010, 10:56 PM
  5. Active X form control
    By amitsingha4u in forum Access
    Replies: 2
    Last Post: 05-18-2010, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums