return PK

S

smk23

I open a form in dialog mode to add new facility to the facility table. This
table is the recordsource for a pull-down on the calling form.

How can I return the value of the new primary key to calling form?

Thanks!!
 
B

Beetle

Your question is a little difficult to understand. I assume by *pull-down*
you mean a combo box, but I don't know what you mean by *calling form*. Is it
part of a Main form/Sub form setup? Or are you moving between two completely
separate forms?

Typically, a combo box can be requeried to update the info, but, again, I'm
not really sure what you are trying to do.
 
G

George Nicholson

One approach:
(Aircode)
************
(From Calling Form:)

DoCmd.OpenForm "MyDialog"

Do While Forms("MyDialog").Visible
' Suspend code until user finishes with Dialog by setting Visible =
False
Do Events
Loop

lngNewPK = Forms("MyDialog").txtFacilityID
DoCmd.Close "MyDialog", acSaveNo
*************
On the Dialog Form, don't close it when done, just set Visible = False. That
gets you out of the loop in the calling form. The calling form closes the
dialog after it has retrieved the desired value.

Other approaches include the use of Public variables, "pushing" the value
from dialog to calling (rather than calling "pulling" it from dialog), etc.
 
J

John W. Vinson

One approach:
(Aircode)
************
(From Calling Form:)

DoCmd.OpenForm "MyDialog"

Do While Forms("MyDialog").Visible
' Suspend code until user finishes with Dialog by setting Visible =
False
Do Events
Loop

lngNewPK = Forms("MyDialog").txtFacilityID
DoCmd.Close "MyDialog", acSaveNo

This can actually be done without the timeconsuming do-while loop by opening
the MyDialog form in Dialog mode:

DoCmd.OpenForm "MyDialog", WindowMode:=acDialog

This will halt execution until MyDialog is either closed or made invisible.
Omit the Do While... Loop code and the remaining code will wait until the form
is hidden to execute. Be sure to put a command button "Close" or "Done" on
MyDialog; its click event should simply be

Private Sub cmdClose_Click()
Me.Visible = False
End Sub

John W. Vinson [MVP]
 
S

smk23

Thanks! Greatly appreciated.
--
sam


John W. Vinson said:
This can actually be done without the timeconsuming do-while loop by opening
the MyDialog form in Dialog mode:

DoCmd.OpenForm "MyDialog", WindowMode:=acDialog

This will halt execution until MyDialog is either closed or made invisible.
Omit the Do While... Loop code and the remaining code will wait until the form
is hidden to execute. Be sure to put a command button "Close" or "Done" on
MyDialog; its click event should simply be

Private Sub cmdClose_Click()
Me.Visible = False
End Sub

John W. Vinson [MVP]
 
G

George Nicholson

Agreed.
I guess I don't use dialog mode all that often or have forgotten the
code-suspension feature it provides. Thanks for the reminder.

But if you don't happen to be using Dialog mode (or want to write code that
will function regardless of the Form's mode), my approach will do the job.
:)
 

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