Requery a combobox

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Requery a combobox

Post by Jeff H »

There is a combobox based on a table of facilities. I made a datasheet form of the table and placed a link to it on the form with the combobox. So far so good. But I can't seem to figure out how to requery the combobox when the facility editing form is closed. I tried using

Code: Select all

Forms!frmPatients!cmbFacility.Requery
in the editing form's Unload event, but that didn't work.

User avatar
HansV
Administrator
Posts: 78235
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Requery a combobox

Post by HansV »

You might requery the combo box in the On Got Focus event of the form that contains this combo box.
Best wishes,
Hans

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: Requery a combobox

Post by Jeff H »

Nope, didn't work. I had tried that with Current and Activate, too. I hadn't tried GotFocus but that doesn't work either.

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: Requery a combobox

Post by Jeff H »

I found a keyboard tip from Tech Republic's Mary Richardson that said to use Shift F9. That works, so it seems like there must be a way to trigger the Requery method in vba.

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: Requery a combobox

Post by Jeff H »

I think I found it. I put that same line in the list editing form's AfterUpdate and that seems to requery the combo on the original form. I notice that after a deletion it shows '#Deleted' at first, but after another edit that goes away and it does accept new data. I'll keep checking it to be sure.

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Requery a combobox

Post by burrina »

After Delete, Me.SomeControl = ""
That should clear it out, just for looks.

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: Requery a combobox

Post by Jeff H »

Thanks burrina. I'll try that.

But I also have a follow up question now. Since I use this same list on more than one form, when the list-editing form is called, I want to pass the name of the calling form with OpenArgs. Unfortunately, I can't see how to integrate the string form name into the code line: Forms![OpenArgs]!cmbFacility.Requeqry.

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: Requery a combobox

Post by Jeff H »

Never mind. I found it. I used

Code: Select all

Dim frm as Form
Set frm = Forms(OpenArgs)
frm!cmbFacility.Requery

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Requery a combobox

Post by burrina »

Congrats