Results 1 to 10 of 10
  1. #1
    Frannilea is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2020
    Posts
    27

    Can't Reference Property or Method on a Button Control

    Hi,

    I'm a teacher writing an app for my students to learn English. I have it almost finished, but a button I had working before suddenly isn't working now for some reason. It's just a simple button to change a table. When the kids finish with the app for the day, they come to me, I see how much candy they've earned and they click the button and say yes to get the candy. However, my button is coming up with the error below. I suspected it has something to do with the textbox above it (that's the text box being referenced) being disabled and locked (I don't want the kids entering in those text boxes above, of course). But even when I enable and unlock the textbox that is referenced in the message, it doesn't fix the problem. That's the only thing I can think of that I changed in this area (during my beautification) that could possibly have changed the function of this button. I'm flummoxed! How could it have been working before, but not now? The only thing I can think of that changed is that property to lock the field from being entered. Please see pictures below.

    Thanks in advance.
    Click image for larger version. 

Name:	Candy Button App Error Pic.jpg 
Views:	27 
Size:	136.7 KB 
ID:	51593
    Click image for larger version. 

Name:	Candy Button Code Error Pic.jpg 
Views:	25 
Size:	134.0 KB 
ID:	51594
    Click image for larger version. 

Name:	Candy Button Properties.png 
Views:	28 
Size:	7.3 KB 
ID:	51595


    Even if I change this to Enabled: Yes and Locked: No, it doesn't fix the problem and produces the same error, so this doesn't solve the problem.

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    try TxtCandyEarned.value (although .value is the default and not needed) rather than TxtCandyEarned .text
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Frannilea is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2020
    Posts
    27
    That worked! Thank you! I'm still puzzled as to why it worked before, but not now, though. I didn't change that at all - as you can probably see by the reference comment above, in my extremely self-internet-taught NOOB ignorance, I 'borrow' code from around the internet and 'fit' it for my new purpose. I simply had ".Text" there because the example did. And I checked an older version (I paranoidly keep a lot of backups in case I screw something up), and the older version definitely worked. Strange...

    Thank you so much!! Reputation added! :-)

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I'm still puzzled as to why it worked before, but not now,
    Then the control must have had the focus at that time? I can't envision any other explanation, as long as in those cases you were still using .Text property.
    It makes no sense to code for your button to get the focus. It already has it, given that the event is the button click event. It's not possible for the focus to be anywhere else given that user has just clicked the button - unless in code you divert focus to somewhere else in that event, and I don't see the code doing that. Also, you cannot set focus to a disabled control. Watch out for the behaviour when an unbound control is edited. If it had a value and you edit that value but don't leave the control, its .Value is what was there before, its .Text is what you changed it to.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I think because it's opening a Msgbox you can't refer to the .text value at that point because the Msgbox receives the focus?
    If you stored the .text value for use in the msgbox function it might have worked?

    All of the above is supposition as I haven't had time to experiment.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    you can't refer to the .text value at that point because the Msgbox receives the focus?
    Can't say whether a message box takes the focus or not; I'm thinking not. However it is modal. The msgbox message can get the control text property value if you give it the focus first. This would work:

    Me.myControlNameHere.SetFocus
    result = MsgBox(Me.myControlNameHere.Text, vbYesNo)

    I still say there is no reason to set focus to the button that runs the procedure.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by Micron View Post
    I still say there is no reason to set focus to the button that runs the procedure.
    I do agree with that, it confused me as well.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    Frannilea is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2020
    Posts
    27
    Thanks for the reply. Yeah, I didn't have the Me.BtnCandy.setfocus there originally at all. I added it after I got the error. It said that 'the control' didn't have focus. I was so confused about WHICH control didn't have focus, after I'd tried enabling and unlocking the TxtCandyEarned textbox (which I first thought was the problem, but that didn't work) so I was messing around trying to give the button focus instead to see if THAT was the problem, lol! (which I also thought was strange, because didn't the user just click on that control??)

    I definitely get the .value thing instead of the .text thing - I just didn't realise there was a .value thing available.

    The error message obviously assumes that the coder is smart enough to know which control it's talking about, lol! Obviously, I wasn't smart enough. :-))

    Thanks for the info. I gave you reputation. :-)

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    If you use the .Text property of a control, it must have the focus.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    WHICH control didn't have focus
    Since there was only one control being referenced in the highlighted line, it could only be that control. If you had referenced more than one and were trying to use a property or method of one of them, then it might still have been a guessing game for you. Should that situation ever arise, you would store the property values in variables (one at a time, after setting the focus) and use the variables instead. Why they made it this way for .Text and not .Value (which as pointed out is the default and need not be specified for this) I'll never know.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 7
    Last Post: 03-09-2018, 11:11 PM
  2. Replies: 15
    Last Post: 05-12-2016, 02:27 PM
  3. Object doesn't support property or method
    By Jamy in forum Programming
    Replies: 7
    Last Post: 07-15-2013, 01:42 AM
  4. object doesnt support this property or method
    By lexygirl in forum Access
    Replies: 1
    Last Post: 12-15-2011, 03:45 AM
  5. Object does not support this method or property
    By Vronsky in forum Programming
    Replies: 5
    Last Post: 05-30-2011, 02:09 PM

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