Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    Combo box selection error

    I have attached a zipped db file, plus two snagit screenshots of the error that I am getting.



    In frmPersonnel, when I select from the combo box Michael Gwynn to remove and click on his name twice
    the following error occurs as shown in the snagit *.pdf file screenshot.

    From there and looking at the code it is clear that it is going to the error section, but it does pass the line up


    On Error goto cboSelectPersonnel_DblCkick_Err


    and goes right to the next executable


    DoCmd. ..


    Then goes to the error, that is strange. You would think that it would go to the error right the On Error line and not move on the next executable line.

    What is wrong? Why am I getting this error.

    I know it has not been upgraded to After_Update yet.

    Any help appreciated. tahnks in advance.


    Respectfully,


    Lou Reed

    I know that it has not been
    Attached Files Attached Files

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    You would think that it would go to the error right the On Error line and not move on the next executable line.
    On Error goto cboSelectPersonnel_DblCkick_Err is not an executable line. It is an instruction to the compiler telling it what to do when an error is generated.

    with regards the error itself. comment out your error goto line and see which line actually generates the error when you run the code.

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Your databases don't work. The main one has no code for the combo, and the "backup" has macro/compile errors.

    (I wish you wouldn't use those embedded macros)

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    This was too easy.... Here is a tutorial on VBA Debugging >> https://www.techonthenet.com/access/...10/debug01.php

    The error I received after connecting the combo box to the code was not in the "Sub cboSelectPersonnel_DblClick".

    In the sub "cboSelectPersonnel_DblClick", set a breakpoint on the call to the sub "updateButtons".
    Click image for larger version. 

Name:	Break1.jpg 
Views:	35 
Size:	74.0 KB 
ID:	29941


    I set a breakpoint in the DCount line to be able to single step through the code. (there is no error handling in the sub)
    I added a Debug.Print line in the "updateButtons" sub to see what the criteria was for the DCount function.
    Click image for larger version. 

Name:	Break2.jpg 
Views:	35 
Size:	48.4 KB 
ID:	29942


    This is what the debug printed:
    Code:
    [PersonnelID] = 1 [isActive] = true
    See anything wrong???

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    This error was dealt with in post #14 of this thread:

    https://www.accessforums.net/showthread.php?t=67370

    When you have a correction to make, please ensure to make it in ALL versions of the database, to avoid encountering the same error again.

  6. #6
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Here is an issue that I have met before. I made the changes in the db.

    I made this change in the comb box select file.

    DoCmd.SearchForRecord,"", acFirst,"[PersonalID]="7[Screen].[ActiveContent]

    You can see it in one of the two pdf files.

    Now when I either save or compile it-it rewrites it as this.

    DoCmd.SearchForRecord,"", acFirst,"[PersonalID]="7[Screen].[ActiveContent]"

    you can see that in the other pdf file.

    This also compiles, but it is clearly not what I want. I want the first one. This even happened when I click on the compact disk icon to save the code.

    How do I stop this. It is really frustrating. I also turned off auto-correct.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files
    Last edited by Lou_Reed; 08-15-2017 at 03:27 PM. Reason: correction

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    This also compiles, but it is clearly not what I want. I want the first one. This even happened when I click on the compact disk icon to save the code.

    How do I stop this. It is really frustrating. I also turned off auto-correct.
    You don't stop it. Because the first one is wrong - go back and look at your code again. It is not what you have copied above. In the first screenshot, the quote marks before [PersonnelID] are missing, creating unbalanced quotation marks. Access is correcting that by adding the closing quote.

  8. #8
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    In the zipped db that is attached to this post< I corrected the mistake in the code to the line

    DoCmd.SearchForRecord,"",acFirst,"[PersonelID]"="&[Screen].[ActiveControl]

    Then I walked through the code and got the combo box select of frmPersonnel. I stopped to the VBA code line that I listed above.

    When I did that, I got an error:

    The expression you entered requires the control to be in the active window

    I am not sure what this means. I Googled the entire phase and got something about MS office software
    was not installed correctly. I do not understand that. I did not even install the MS Office software.

    What is the cause of this error?


    Also, I want to walk through some code I the updatebuttons SUBs. However, each of two forms that has the uodatebuttons SUBs are
    subforms. I must load the parent form I order to get to see these subforms.

    That would be easy if I knew what each subform had as a parent form. Again that is easy just look at the
    name and do some matching up.

    That works most of the time - but not in the two cases that I am posting about here.

    The cases are sfrmPropertyPass1 and sfrmTelework1. I do not see the parent form for each of these subforms.

    There must be something in their properties sheet that could tell me that.

    Is there?

    Any help appreciated. Thanks in advance.


    Respectfully,

    Lou Reed
    Attached Files Attached Files

  9. #9
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, I got the answer to the second question in that I can find the parent form now from the sfrmPropertyPass1 and sfrmTelework1. Now I am going to modify the combo boxes so the list is populated. However, I still cannot find an answer to the first problem.

    The one that generates the error:

    The expression you entered requires the control to be in the active window.

    What must I do to get that error corrected?

    Any help appreciated. Thanks in advance.

    Respectfully,


    Lou Reed

  10. #10
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The expression you entered requires the control to be in the active window
    The "active window" is the one you see on the screen, and is not behind another one. So, when you are in the form, it is the active window so there is a control to refer to. But when you open the code window to step through the code, the form is no longer the active window (the code window is), and there are no controls on it, so you get the error.

    What I suggest you do is change the somewhat vague reference [Screen].[ActiveControl] to an explicit reference to the form control:

    DoCmd.SearchForRecord,"",acFirst,"[PersonelID] = " & forms!frmPersonnel!PersonnelID

    There are two advantages to that. First, when you or anyone else reads the code, you know exactly what is being referred to and second, if you move that code to another control event (a search button On Click for example), it will still work.

  11. #11
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The control name is "Combo170" (was "cboSelectPersonnel"). The field "PersonnelID" is the first field in the combo box row source & the bound field.

    So you could use:
    Code:
        DoCmd.SearchForRecord , "", acFirst, "[PersonnelID] = " & Me.Combo170

    ** (Thanks, John...... I missed the control name change - I used an older dB from a different post)
    Last edited by ssanfu; 08-16-2017 at 07:40 PM. Reason: edited control name

  12. #12
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Thanks, I missed that - except that in the last version above, it has become Cbo170!

    Lou: Any reason for the new name for the combo?

  13. #13
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    The reason for Cbo17 is that I erased the original Cbo here and created another one, I took the name the software gave me. Bill Gates gave it that name not me.So ask him.

    However, when I substituted forms!frmPersonnel!PersonnelID for [Screen].[ActiveControl] I got the 2487 error.

    I will now do the second suggestion and see if it works.

    Thanks for your help.

    BTW, this is quite subtle. Why how did you know to do this?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  14. #14
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I am still getting the MS Access error 2487. I have included the zipped db file and the snippet shot of the screen output showing the error.

    What can I do to fix this?

    Respectfully,

    Lou Reed
    Attached Thumbnails Attached Thumbnails Capture.GIF  
    Attached Files Attached Files

  15. #15
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I cannot replicate that error; the double-click works fine. But I'm using Access 2016, so maybe A2010 doesn't like something.

    Try changing this: DoCmd.SearchForRecord , "", acFirst, "[PersonnelID] = " & Me.Combo170
    to this: DoCmd.SearchForRecord , , acFirst, "[PersonnelID] = " & Me.Combo170,

    i.e. remove the zero-length string ("") and leave the argument completely blank. You still need all the commas, though. Generally speaking, it is not good practice to use "" for an argument - it's better to let Access deal with what to do if an argument is not there.

    I see nothing wrong with your code (other than the zero-length string), so the error may be somewhere else. If you still get an error message, click "Debug" and Access will show you the code where the error is, with the offending line highlighted.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 02-07-2017, 05:19 PM
  2. Replies: 7
    Last Post: 03-30-2015, 10:04 AM
  3. Replies: 5
    Last Post: 04-09-2014, 06:57 PM
  4. Replies: 3
    Last Post: 07-03-2013, 10:38 AM
  5. Replies: 1
    Last Post: 10-30-2012, 10:29 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