Open Form and wait for Selection Before Contuning with Code

D

Daniel

Hello,

As the subject stated. I have bit of code which open a form, populates the
listbox contain within it (not working yet). I need the code to wait until
the user make a selection (or presses a button) before going on to finish my
code. how can this be done?

My code is:
Set rst = db.OpenRecordset(strSQLNew)
DoCmd.OpenForm "Duplicate Clients", , , , , acDialog

rst.MoveFirst
Do While Not rst.EOF
Forms![Duplicate Clients].Form.List0.AddItem Item:=rst![ClientID]
rst.MoveNext
Loop
'I would need it to pause here until the user make a choice, right after
populating the listbox
....

Thank you for your help,

Daniel P
 
D

Dirk Goldgar

In
Daniel said:
Hello,

As the subject stated. I have bit of code which open a form,
populates the listbox contain within it (not working yet). I need
the code to wait until the user make a selection (or presses a
button) before going on to finish my code. how can this be done?

My code is:
Set rst = db.OpenRecordset(strSQLNew)
DoCmd.OpenForm "Duplicate Clients", , , , , acDialog

rst.MoveFirst
Do While Not rst.EOF
Forms![Duplicate Clients].Form.List0.AddItem
Item:=rst![ClientID] rst.MoveNext
Loop
'I would need it to pause here until the user make a choice, right
after populating the listbox
...

Thank you for your help,

Daniel P

Your code to load the list box via AddItem won't be executed until after
the form "Duplicate Clients" is closed or hidden, because that form is
opened in dialog mode. I suggest you use code in the dialog form itself
to load its list box. If doing so needs information from your current
form -- the SQL of the query, maybe -- you can pass it to the form via
the OpenArgs argument of the OpenForm method.

Then, after the user has made his selection on the dialog form, you can
hide the form instead of closing it, to allow your code to continue and
pick up the selection from the list box. After that, the code can close
the form.
 
D

Daniel

Thank you Dirk! I can't count the times you've enlighten me with simple
solutions to my problems!!!!

Daniel P





Dirk Goldgar said:
In
Daniel said:
Hello,

As the subject stated. I have bit of code which open a form,
populates the listbox contain within it (not working yet). I need
the code to wait until the user make a selection (or presses a
button) before going on to finish my code. how can this be done?

My code is:
Set rst = db.OpenRecordset(strSQLNew)
DoCmd.OpenForm "Duplicate Clients", , , , , acDialog

rst.MoveFirst
Do While Not rst.EOF
Forms![Duplicate Clients].Form.List0.AddItem
Item:=rst![ClientID] rst.MoveNext
Loop
'I would need it to pause here until the user make a choice, right
after populating the listbox
...

Thank you for your help,

Daniel P

Your code to load the list box via AddItem won't be executed until after
the form "Duplicate Clients" is closed or hidden, because that form is
opened in dialog mode. I suggest you use code in the dialog form itself
to load its list box. If doing so needs information from your current
form -- the SQL of the query, maybe -- you can pass it to the form via
the OpenArgs argument of the OpenForm method.

Then, after the user has made his selection on the dialog form, you can
hide the form instead of closing it, to allow your code to continue and
pick up the selection from the list box. After that, the code can close
the form.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

In
Daniel said:
Thank you Dirk! I can't count the times you've enlighten me with
simple solutions to my problems!!!!

You're welcome, Daniel. I'm always glad to help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top