closing a form when opening another form

D

Dan

I have a form that opens a popup form and this form takes the the user to a
specific record in the first form, using a command button. I want to close
the popup form once the the focus returns to the first form. I've tried
macros and adding a docmd string to the command buttons event procedure. I've
tried the macro on exit and lost of focus properties of the pop up form and
even on gotfocus in the first form. Nothing works. Any clue for the clueless?
 
K

kabaka

I would use

sub Cmd_OnClick()

...all your other code...
docmd.close acform, me.name

end sub

in the click event of the command button on the pop up form; but you say
that doesn't work? What is the code you're using?
 
G

George Nicholson

The following is a suggestion to rethink your approach a bit. One advantage
of the following method is that it keeps the popup from getting too
specialized. As it stands, you can only use it for one thing. If you keep it
more generic, it will be easier to use the form if you have a future need
for a simple "select a record" popup (say, to build report criteria?). The
Popup should simply allow the user to select a value. Any "specialized" code
that uses that value becomes the responsibility of the routine that opens it
(plus: you deftly avoid the always annoying lostFocus, Deactivate, yada,
yada issues).

'***************
Main Form (aircode):
docmd.OpenForm "Popup"
Do while popup.visible = true
do events
loop

(On popup: when User makes selection, set popup.visible = false)

' Popup is now hidden
- Add Code to get selection value from hidden popup
DoCmd.Close acForm "Popup"
- Add Code to move to specified record on main form & set focus
'****************
HTH,
 
Top