Results 1 to 7 of 7
  1. #1
    djrivers is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    4

    OnClick event in an image control not able to return value in a textbox control on the same form in

    I am not sure what am I doing wrong. In a form, I used to have a command button control with VBA function in it. And one of the procedure is to read the value in a textbox in that same form. It works fine but when I tried to put an image control and put a procedure in its onclick event to read the value of the same textbox, it returns NULL. Am I missing a difference in terms of using the onclick event between a command button control and image control? I'm attaching the file that mimics the issue that I'm having. There's a description there on how to produce the problem.

    Thanks,


    Darren
    Attached Files Attached Files

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You just need to move the focus away from the textbox and it will then work correctly

    Create an after update event for the textbox and add the line
    Me.Command8.SetFocus
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    djrivers is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    4
    Hi Ridders52. Thanks for the reply. That may work. I was just hoping that it will be as easy as coding a command button. It's just weird that it's a same onclick event but reacts differently. Where I'm actually using this method is on a logical statement that checks is the textbox IsNull. I used to have a button where the method was attached then I just decided to us an image instead and that how I discovered the issue. It works fine if you use a button control but not with an image control.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by djrivers View Post

    ...It's just weird that it's a same onclick event but reacts differently...
    It's not the OnClick events that are acting differently! The difference in function, here, is caused because a Command Button can receive Focus...but an Image Control cannot...and until Focus leaves the Textbox... txtTextCopy has no Value.

    When you click on the Command Button, Focus is moved away from txtTextCopy...when you click on the Image Control, Focus remains on the Textbox.

    Hence Colin's correct suggestion that you need to move Focus away the txtTextCopy before executing the rest of your code that is dependent on its Value.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    djrivers is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    4
    Finally, an answer to the mystery that is really not a mystery haha. Thank you so much Missinglinq for clarifying what's actually happening. New learning for me. Thank you too again ridders52 for giving me an idea on how to make it work.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You're welcome
    To avoid confusion, I tend to avoid using images as command buttons especially in forms which contain 'normal images' as well
    Are you aware you can include images as well as text on command buttons. For example:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	9 
Size:	2.0 KB 
ID:	34289
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    djrivers is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    4
    Quote Originally Posted by ridders52 View Post
    Are you aware you can include images as well as text on command buttons.
    Yup. Although I haven't explored that option much yet.

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

Similar Threads

  1. Replies: 3
    Last Post: 07-13-2015, 12:07 PM
  2. Replies: 3
    Last Post: 05-14-2015, 01:07 PM
  3. Replies: 13
    Last Post: 04-29-2015, 09:24 AM
  4. zoom control for image on form
    By oldtiredjeffro in forum Forms
    Replies: 7
    Last Post: 10-20-2014, 03:30 PM
  5. Help with Onclick event to refresh textbox.
    By mikeone610 in forum Access
    Replies: 3
    Last Post: 02-07-2013, 03:58 PM

Tags for this Thread

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