Waiting for input from a form

R

Rod

Half-way through my code, the user needs to supply information from a
combo-box.

How do I pause my code while the user makes their selection? I cannot use
InputBox or MsgBox, since I need the combobox object. How do I open an
ordinary form and then wait for the user to press "OK" (or whatever button I
create) before continuing to execute the code? Setting the Modal property to
Yes doesn't help.

Thanks
 
D

Douglas J. Steele

Why not open the form using acDialog?

DoCmd.OpenForm "MyForm", WindowMode:=acDialog


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Pieter Wijnen"
 
J

John Spencer

Can't you get the value before you start the code and just pass it in as an
argument?

If for some reason the answer is no, then try this technique.
Open the form in acDialog mode.
Hide the form when your user has input data (code the ok button to set the
form's visible property to false.
Check if the form is open and if so grab the value(s) you need
Close the form

..... Your code

'Stop processing in current procedure until form closes or is no longer
visible
DoCmd.OpenForm "YourFormname", windowmode:=acdialog
If isFormLoaded = True Then
someVariable = Forms!YourFormName!YourControlName
DoCmd.Close acForm, "YourFormname"
End if

.... resume processing your code

'Sample code to check if form is loaded (works for all versions of Access up
to 2003 and probably 2007 (not tested)

Function IsFormLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet
view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsFormLoaded = True
End If
End If

End Function
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
P

Pieter Wijnen

Since he said that modal mode didn't work <g>
Can happen when timers are involved

Pieter
 
D

Douglas J. Steele

I read that as meaning he tried to set the form's Modal property to True,
which I believe is different that opening it using acDialog.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Pieter Wijnen"
 
P

Pieter Wijnen

It shouldn't be, I think. At least not as far as I recall.
I do offcourse use the acDialog Param to make sure myself, but always also
add the (superfluos) waiting loop to make sure it works under any
circumstances.

Pieter
 
R

Rick Brandt

"Pieter Wijnen"
It shouldn't be, I think. At least not as far as I recall.
I do offcourse use the acDialog Param to make sure myself, but always also add
the (superfluos) waiting loop to make sure it works under any circumstances.


Modal won't relinquish focus, but it does not pause code from a calling form
like acDialog does.
 

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