By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,835 Members | 1,951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,835 IT Pros & Developers. It's quick & easy.

Requerying a ListBox upon returning from a modal form

P: n/a
In Access 2000, I have a base form with a ListBox of conference
registrants. In the form's declarations section I include

Dim f as Form

To add a registrant I'm doing this:

Set f = New Form_frmSingleRegistrant
f.Caption = "New Registrant"
f.cmdSave.Caption = "&Save New Registrant"
f.Visible = True

(And if editing instead of adding, similarly but with more code.) So
the add/edit form opens, I do whatever I'm doing, and it closes and
I'm back to the original list form.

The Problem: If I edit, the main form ListBox shows the updates when
I return; but if I add a new record, the ListBox doesn't requery and
the newly-added record isn't shown. I've tried every conceivable
event to requery it (without requiring a click on the form first) but
none work; when the subform closes, apparently no events are triggered
on the original form.

So my question, for anyone kind enough to help: Is there any way to
get this ListBox to requery? I realize, of course, that I could bring
up the subform in other ways, but I'm wondering if there's a way to
make it work this way.
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Kyralessa" <ry********@hotmail.com> wrote in message
news:27**************************@posting.google.c om...

The Problem: If I edit, the main form ListBox shows the updates when
I return; but if I add a new record, the ListBox doesn't requery and
the newly-added record isn't shown. I've tried every conceivable
event to requery it (without requiring a click on the form first) but
none work; when the subform closes, apparently no events are triggered
on the original form.


I'm not any sort of expert in Access programming, but I figure it works
the pretty much the same as VB.

In your "main" form code you're displaying a modal form that acutally
does the registrant add.

Once control returns to your main form, you don't have to look for some
event,
just put your requery code directly after the line of code that displays the
modal form.

The flow would be someting like this:

User decides to add new registrant
Your code displays the modal "Add registrant" form
the flow of control passes to the modal form
the modal form does it's thing and adds the registrant
the modal form exits and unloads itself
the flow of control passes back to the "main form"
The main form forces the listbox to refresh
In mainform code:

frmAddRegistrant.Show vbModal
lstboxRegistrant.Refresh ' or whatever you're using to requery

Simeon
Nov 12 '05 #2

P: n/a
"Simeon Nevel" <sn****@sonic.net> wrote in message news:<qb********************@typhoon.sonic.net>...
Kyralessa" <ry********@hotmail.com> wrote in message
news:27**************************@posting.google.c om...

The Problem: If I edit, the main form ListBox shows the updates when
I return; but if I add a new record, the ListBox doesn't requery and
the newly-added record isn't shown. I've tried every conceivable
event to requery it (without requiring a click on the form first) but
none work; when the subform closes, apparently no events are triggered
on the original form.
I'm not any sort of expert in Access programming, but I figure it works
the pretty much the same as VB.

Well, um, no, it doesn't. (Probably that's why I was bringing up the
question in an Access group instead of a VB group.)

In your "main" form code you're displaying a modal form that acutally
does the registrant add.

Once control returns to your main form, you don't have to look for some
event,
just put your requery code directly after the line of code that displays the
modal form.

In mainform code:

frmAddRegistrant.Show vbModal
lstboxRegistrant.Refresh ' or whatever you're using to requery

This doesn't work in Access VBA because (a) there's no Show method,
and (b) putting the refresh/requery after the f.Visible=True line, the
refresh/requery executes right away rather than after the add/edit
form is closed, even though that form is set to be Popup and Modal.
Nov 12 '05 #3

P: n/a
On the OnClose event of the modal form, add a line to requery the
listbox:

Forms!MainForm!Listbox.requery

Kyralessa wrote:

In Access 2000, I have a base form with a ListBox of conference
registrants. In the form's declarations section I include

Dim f as Form

To add a registrant I'm doing this:

Set f = New Form_frmSingleRegistrant
f.Caption = "New Registrant"
f.cmdSave.Caption = "&Save New Registrant"
f.Visible = True

(And if editing instead of adding, similarly but with more code.) So
the add/edit form opens, I do whatever I'm doing, and it closes and
I'm back to the original list form.

The Problem: If I edit, the main form ListBox shows the updates when
I return; but if I add a new record, the ListBox doesn't requery and
the newly-added record isn't shown. I've tried every conceivable
event to requery it (without requiring a click on the form first) but
none work; when the subform closes, apparently no events are triggered
on the original form.

So my question, for anyone kind enough to help: Is there any way to
get this ListBox to requery? I realize, of course, that I could bring
up the subform in other ways, but I'm wondering if there's a way to
make it work this way.

Nov 12 '05 #4

P: n/a
Norman Scheinin <no***************@boeing.com> wrote in message news:<3F***************@boeing.com>...
On the OnClose event of the modal form, add a line to requery the
listbox:

Forms!MainForm!Listbox.requery


Thanks, Norman; that gave me a nudge in the right direction. I tried
it and got error 2118, but a bit of searching got me here:

http://dbforums.com/showthread.php?s...97#post1530197

Odd, but it works; if at the end of the "Save" routine on the Add/Edit
form I do

Forms("MainForm").lstRegistrants.Value = Null
Forms("MainForm").lstRegistrants.Requery

then when I get back to the main form, it's updated with the new
registrant.
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.