List Box anomaly

Copper Contributor

I have a multi-user Access application -- each user has a client piece locally, all looking at a single Access database with the table data on a company network.

A form on that client application (let's call it Form1) has a number of objects, including a list box and several buttons.  The form itself is unbound.  One button has some code for the OnClick event, and all the VBA code behind the click event does is simply open open another form (call it, Form2).  But, when I click that button on Form1 to open Form2 (which is also an unbound form), I can see that the list box on Form1 requeries (or refreshes -- I can't tell).  There is nothing in the VBA code to requery the listbox on Form1.

Has anyone ever encountered such an anomaly or have any thoughts on what might be causing this anomaly?

12 Replies

@RichNewman 

Unfortunately, without SEEING the actual code, it's impossible to guess what might be happening.

To share the code, you can open the form in design view and select the VBA for the button's click event. Copy it all and paste it here. That way someone might be able to spot a line that could be causing this.

 

 

@George Hepworth 

 

Thanks for the prompt reply.  Here is the code, but it's really amazingly simple..

 

Private Sub Command6_Click()
     Dim stDocName As String
     Dim stLinkCriteria As String

     stDocName = "frmContractAdd"
     DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

 

@RichNewman 

At what point do you see the refresh or requery happen? 

 

@RichNewman 

Also, what happens in that second form, "frmContractAdd"? Is it adding a new contract to the table which is also the row source for this list box, by any chance?

As soon as I click that button.

When I was developing this, I used a copy of the production data placed on my laptop and linked to the tables in that local copy, just to improve performance. When I do that, this odd requerying action does seem to happen now that I'm looking closer, but so quickly that nobody would notice unless they tried. Likewise, when everyone was working in the office last year, the response time was much better. Now that folks are working from home with slower response times (varies by user of course) the requerying is much more noticeable, and one person shared her desktop with me and I saw that underlying list box requery a few times, very slowly. The odd behavior does seem to be specific to the listbox on the first form where the button to open the second form lives. The second form is to add a record to the database, and when that is done, and I close that 2nd form, then in that case there is an explicit requery of the listbox to display the added or modified record in the listbox. But this is happening before we even get that far.

@RichNewman 

 

Thank you. That was going to be my suggestion, in fact. So you see this requery even without closing the second form and BEFORE using it to add a new contract?

 

Correct. The second form to add a contract is a modal popup that users have to fill in. They click a button on that popup, I run some editing checks, and when it passes I add the record to the database, close the second form, and force a requery on the listbox in question on the first form. That particular requery is intentional and I see that in the code. But the one described above on that first form where I just clicked to bring up the popup seems inexplicable to me -- at least insofar as looking at the code. (We all makes mistakes, of course, and I'm no different. But I've been coding Access with VBA for about 15 years, so I'm pretty good at spotting coding issues. Something else is afoot here.)

@RichNewman 

One more test comes to mind then. Open the contract form, then immediately close it without adding a new contract or doing any of the other validation. Simply open and close it. Does that still cause the unintentional requery? 

 

Keeping in mind that processing in the calling form would be suspended until the called modal is closed, is there possibly some other event in the calling form that is pending until the contract form closes again? Maybe a timer event? 

The unintentional requery happens before the user even makes a decision to add a contract or just close the popup with no changes. They just have to click the button to open the popup. By the way, it's not just the "Add Record" button. On the first form, there's also a button to delete a record. The user selects a record to delete from the list box in question, then clicks the Delete button, I throw up a warning message to be sure they want to perform the delete, if they affirm, I delete the selected record, and then I explicitly requery the list box (no additional form has been opened). In this case, the moment I click "Delete", I see the list box requerying, and again, I didn't even open a new form.

@RichNewman hm. That suggests the problem is not in the called form, then, but in the calling form. It is requerying the list box based on some internal event. As soon as it loses focus to the message box or to the called popup, something forces that requery. What other event(s) are in that form? Anything that could be going on there?

Also, is this on a subform or in a main form? It occurs to me that subforms do exhibit that repeated requery behavior when loading. Is that possibly involved?

There's no sub-form. The form that contains the listbox in question has only one event procedure that executes OnOpen. There's nothing for the OnGotFocus or OnLostFocus events, though I see where you were headed there.

@RichNewman 

 

I wonder if you've found the place where the requery is being triggered. If you'd like, I could take a look. Can you provide a sample copy of the accdb with any personal or confidential data removed?