Results 1 to 12 of 12
  1. #1
    timesscript is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    34

    Using list box to select records causes form to jump temporarily to first record


    I have a list box that I set up by choosing to add a list box, and selecting "find a record on my form based on the value I selected in my list box." This will then populate the other controls in my form based on the record selected,

    It works to choose the record, but when I choose a record on the list box, it will jump to the first record and display its info in my controls for a split-second, before it settles on the correct record. The status bar says "Calculating..." while this takes place.

    If I select a record just using the back and forward options on the form, this does not happen (though it still says "calculating...")

    Any thoughts on how to solve this?
    Last edited by June7; 05-12-2015 at 01:43 PM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The listbox is UNBOUND?

    This is why I avoid the wizards - they do stuff I don't like. Did it generate a macro or VBA? Need to review code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    timesscript is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    34
    It is unbound, though I am a beginner and am not sure what that implies, but here is the macro it created:

    Click image for larger version. 

Name:	macro.PNG 
Views:	18 
Size:	8.6 KB 
ID:	20667

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    UNBOUND means the ControlSource is not set to a field. It is blank or has an expression.

    I don't see anything wrong with that code but I don't use macros, only VBA. It always baffles me why the wizard puts the = sign at beginning of the expression. Seems unnecessary.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    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
    To search for a Record, you have to tell Access where to start the search. When you select the action SearchForRecord, the default for the third argument ('where to start') is the First Record, hence the

    Record First

    in the third line under SearchForRecord in the Macro definition. My guess, and it is just a guess (almost no one here uses Embedded Macros, including myself) is that when doing this through a Macro, it runs relatively slow, allowing you to actually see the First Record briefly.

    I would delete the Macro from the AfterUpdate Property, in the Properties Pane, and use this code, instead:
    Code:
    Private Sub List269_AfterUpdate()
      
     Dim rs As Object
    
     Set rs = Me.Recordset.Clone
       rs.FindFirst "[Full Name] = '" & Me![List269] & "'"
     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    
    End Sub

    I suspect that this will solve your problem.

    Linq ;0)>

  6. #6
    timesscript is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    34
    Missinglinq,

    That did indeed solve the problem. I wonder why Microsoft didn't have it work that way in the first place!

    Thanks!

  7. #7
    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 timesscript View Post

    ...I wonder why Microsoft didn't have it work that way in the first place...
    They did...until Access 2007! Then the Boys of Redmond, for some obscure reason, started trying to coerce everyone into using Embedded Macros, instead of VBA code, by making Embedded Macros the default for events. The problem is that EMs

    1. Use an arcane language their own
    2. Don't offer the flexibility that VBA does
    3. Offer no real advantage over VBA

    In fact, they actually present some disadvantages, as you've seen, by executing Macros slower than comparable code! In this case, because the Macro executes slower than the code, you actually get a glimpse of the first Record when Access moves to it!

    Because of this, very few experienced developers routinely use Embedded Macros.

    If your copy of Access had been set up with the option 'Always Use Event Procedures' selected, when you used the Combobox Wizard to create your 'search' function, Access would have generated VBA code just like I gave you, instead of a Macro!

    If you're interested in using/learning VBA code, you can set your Access to make that the default by going (in 2007, at least) to Options - Object Designers - Forms/Reports and ticking the box for the Always Use Event Procedures option.

    Aside from offering more flexibility in what you can do, and how you can do it, VBA has one more big advantage...everyone here uses it, and will happily help you with advice, and almost no one here uses Macros...and hence can't help you with them!

    Linq ;0)>

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I find the 'Always Use Event Procedures' is inconsistent. I just tried it with a button. Wizard still generated embedded macro. However, when I clicked the ellipsis in the event property, it shows [Event Procedure] and opens the VBA editor at the procedure - instead of popping up Choose Builder dialog box.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    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
    Been a while since I diddled with this, but it seems like you can't change the option and have it go into effect immediately. In other words, the mode it is in when then file is originally created remains the mode, for that file, regardless of what you do with the option later.

    Linq ;0)>

  10. #10
    timesscript is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    34
    Hmmm... so I have come upon a new and strange problem with this listbox. The error below is popping up when I select anything. However, if I then go into the form and bring up the vba code for that event procedure, do not edit it, but leave the window open, it works when I switch it back to form view. It will then continue to work if I close the vba code, until I close the database and reopen it, when I begin getting the error again when I click on the list box.
    Click image for larger version. 

Name:	Capture.PNG 
Views:	9 
Size:	9.3 KB 
ID:	20771

  11. #11
    timesscript is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    34
    A decompile and recompile fixed it.

  12. #12
    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
    Glad you got it fixed. For future reference, you really need to start a new thread, with an appropriate title, when you have a new problem. A title of "Using list box to select records causes form to jump temporarily to first record" is not apt to give you help for your current problem!

    Linq ;0)>

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

Similar Threads

  1. How to Open form and jump to certain record?
    By behnam in forum Programming
    Replies: 3
    Last Post: 06-05-2014, 08:45 AM
  2. Using a Combo Box to jump to a record
    By Access_Novice in forum Forms
    Replies: 3
    Last Post: 11-19-2013, 04:14 PM
  3. Replies: 3
    Last Post: 08-26-2012, 10:04 PM
  4. Text Box - Jump to Record
    By drow in forum Forms
    Replies: 5
    Last Post: 03-12-2012, 11:25 PM
  5. How to jump on a new record when forms open?
    By braveali in forum Programming
    Replies: 3
    Last Post: 02-21-2012, 08:17 AM

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