List box refresh

I'm thinking this wouldn't cause enough performance issues to be a concern for this application and environment. In this situation it is more desirable to have the functionality than to optimize for speed. (If I'm understanding your comment)
 
I should remind you that the After Update event of the textbox fires when (after altering or entering) text you move out of the textbox. If you're happy with this then:

Docmd.Runcommand accmdsaverecord
 
Thank you, yes, that's good. I noticed that when I delete a record the form automatically sets itself into "add a new record mode" as if I had pressed the Add button (ie, it 1)shows blank fields and 2) shows are editing record 3 of 3 when there are now only 2 actual records remaining with data - the third was just deleted). It's not until I click another item in the list box that another actual record is shown in the form's text boxes and the number of records is reduced by 1 (to reflect the deletion of the previous record by the delete button). I tried using "setfocus" as the last command in the delete button's click event to set the focus on the list box, and while it does focus on the list box, it doesn't actually highlight any items in the list box, therefore not causing the form to show a record and allowing the form to be in add-a-record mode and not reducing the number of records (as described just previously). Is there a way I can

1) use code instead of macro to cause the record highlighted in the text box to be selected for the form (is a new question)?

2) cause an item in the txt box to be highlighted after another is deleted with the delete button (which would cause an existing record to be shown in the form and prevent the form from being add-a-record mode)?

Thanks again.
 
What you have described will ONLY happen when you have deleted a NEW record. That code I gave you is the default behaviour of the built-in delete button. If you delete an old record it will NOT go to a blank form.

I think you need to understand how the form works because most of what you're saying shows you don't understand the default behaviour of a form.

Question 1 is unclear. Please explain?
 
When I created the list box I used the wizard to create it and selected the option in the wizard saying, "Find a record on my form based on the value I select in my list box". It looks like the wizard uses a macro for the functionality instead of vba code on the list box's events. Can you tell me the code that is equivalent to the macro so I can use it instead? Thanks.
 
Open the macro and copy and paste what's in the Arguments box in here. I suspect the Action is SearchForRecord.
 
Thanks, vbaInet.

I thought I'd share what I've found with future searchers. First, although there is the known bug in Access 2010 when trying to convert a form's macros to code, I found the following work around.

On the macro viewing screen, "collapse" the macro, then right click it and copy it. Then create a new macro and paste the copied one into the new/blank macro. Then the conversion can be done successfully and will produce vba code equivalent to the macro's functionality.

Doing that produced this line of code that, placed in the After Update event of the list box, takes the place of the macro:

DoCmd.SearchForRecord , "", acFirst, "[buildingName] = " & "'" & Screen.ActiveControl & "'"
 
Good to hear you found a workaround. You could have tried SAVE AS and save it as a Module.

So, change Screen.ActiveControl to Me.List22.Value
 
Gotcha. I can see uses for it both ways. Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom