Help with Modal Popup form

D

dchendrickson

I am using Access2002 / XP Pro.

I am working with a main form and a popup form. When the
OK button on the main form is clicked, the cmdOK_Click()
event procedure determines if the popup needs to be
opened based on certain criteria. The popup lets the user
choose between Overwriting the current record with new
information, or ADDing a new record based on the
information.

The popup contains a label (for messages) and two
buttons. The form has Allow Edits=true, popup=true,
modal=true, borderstyle=dialog. The OnClick events for
each button set the value of a global boolean and then
close the popup. The global boolean is used to determine
the choice of the user.

Based on another posting here, I am opening the popup with
Dim frm as Form
Set frm = ....
....
DoCmd.OpenForm frm.Name, acNormal, , , , acDialog

I am using the acDialog setting to stop the program flow
of the main code (cmdOK_Click) until the user clicks a
button. But I am having some problems.

I need to open the popup and change the caption of its
label. But if I set a variable equal to the label control
of the unopened form, assign my new label string to
label.caption, then execute the ...OpenForm method, the
label does not show the new string. If I put the command
to update the label after the OpenForm method, the
program is paused for input and never gets there.

Next problem: There is no close button on the popup. The
last line of the code for each button on the form is:

DoCmd.Close acForm, "popOverWriteAdd", acSaveNo

The theory is to click the button of choice, the code
sets the value of the boolean and then closes the form.
But the form won't close. Do I need to change the focus
back to the main form before I can close the popup? Or is
there another issue?

Ideally, I would like to have the popup behave exactly
like the msgbox function, but be able to put my own
Caption on the buttons. Class Modules and functions at
that level are above my abilities at this time. Is there
something 'off the shelf' that I could use?

I know this has several different issues wrapped into one
posting, but thanks for your help.

-dc
 
G

Graham Mandeno

Hi DC

The trick is to pass the information to the form using the OpenArgs
mechanism:
DoCmd.OpenForm frm.Name, acNormal, , , , acDialog, _
"This message will be displayed in the label"

Then, in the popup's Form_Load procedure:
Me.lblMessage.Caption = Me.OpenArgs

You can invent your own protocol for passing multiple values via OpenArgs,
perhaps by concatenating them with a delimiter character like vbTab. The
Form_Load proc then has to pick it apart to decide what is a message and
what is a button caption, etc.

When it comes to passing control back to the calling procedure, an
often-used method is to have the modal form hide itself:
Me.Visible = False

This allows the calling procedure to continue its execution. It can extract
values from controls on the modal form and then close it.

However, the method you are using (set global variable(s) then close myself)
should work. Are you sure that no error is occuring which is being ignored
(perhaps with On Error Resume Next)?

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.
 
D

dchendrickson

Ken & Graham,

The OpenArgs mechanism is just what I needed. I had never
used it before and really wasn't aware of it.

As for the other program flow problems I was having...
well they fixed themselves overnight. I got frustrated
and left for the day in order to come back with a fresh
mind in the morning. Got things fired up this AM and
everything worked just as I had been attempting.

There must have been some fly in the ointment that a
simple shutdown and restart fixed....

Now I am have troubles with the display of the text...
but that issue has its own posting.

Thanks for the info and for adding another tool to my
skull.

-dc
-----Original Message-----
Hi DC

The trick is to pass the information to the form using the OpenArgs
mechanism:
DoCmd.OpenForm frm.Name, acNormal, , , , acDialog, _
"This message will be displayed in the label"

Then, in the popup's Form_Load procedure:
Me.lblMessage.Caption = Me.OpenArgs

You can invent your own protocol for passing multiple values via OpenArgs,
perhaps by concatenating them with a delimiter character like vbTab. The
Form_Load proc then has to pick it apart to decide what is a message and
what is a button caption, etc.

When it comes to passing control back to the calling procedure, an
often-used method is to have the modal form hide itself:
Me.Visible = False

This allows the calling procedure to continue its execution. It can extract
values from controls on the modal form and then close it.

However, the method you are using (set global variable (s) then close myself)
should work. Are you sure that no error is occuring which is being ignored
(perhaps with On Error Resume Next)?

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.

I am using Access2002 / XP Pro.

I am working with a main form and a popup form. When the
OK button on the main form is clicked, the cmdOK_Click ()
event procedure determines if the popup needs to be
opened based on certain criteria. The popup lets the user
choose between Overwriting the current record with new
information, or ADDing a new record based on the
information.

The popup contains a label (for messages) and two
buttons. The form has Allow Edits=true, popup=true,
modal=true, borderstyle=dialog. The OnClick events for
each button set the value of a global boolean and then
close the popup. The global boolean is used to determine
the choice of the user.

Based on another posting here, I am opening the popup with
Dim frm as Form
Set frm = ....
....
DoCmd.OpenForm frm.Name, acNormal, , , , acDialog

I am using the acDialog setting to stop the program flow
of the main code (cmdOK_Click) until the user clicks a
button. But I am having some problems.

I need to open the popup and change the caption of its
label. But if I set a variable equal to the label control
of the unopened form, assign my new label string to
label.caption, then execute the ...OpenForm method, the
label does not show the new string. If I put the command
to update the label after the OpenForm method, the
program is paused for input and never gets there.

Next problem: There is no close button on the popup. The
last line of the code for each button on the form is:

DoCmd.Close acForm, "popOverWriteAdd", acSaveNo

The theory is to click the button of choice, the code
sets the value of the boolean and then closes the form.
But the form won't close. Do I need to change the focus
back to the main form before I can close the popup? Or is
there another issue?

Ideally, I would like to have the popup behave exactly
like the msgbox function, but be able to put my own
Caption on the buttons. Class Modules and functions at
that level are above my abilities at this time. Is there
something 'off the shelf' that I could use?

I know this has several different issues wrapped into one
posting, but thanks for your help.

-dc


.
 

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