return PK

  • Thread starter Thread starter smk23
  • Start date Start date
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!!
 
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.
 
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.
 
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]
 
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]
 
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.
:-)
 
Back
Top