Form That Makes it Impossible to Click on Other Forms?

D

DoveArrow

You know how when you get an error, and a little message box pops up
that forces you to click on the OK button before you can do anything
else? Can you do that with forms? Let me know, because I'd like to do
something that with a database I'm working on. Thanks.
 
D

Dirk Goldgar

DoveArrow said:
You know how when you get an error, and a little message box pops up
that forces you to click on the OK button before you can do anything
else? Can you do that with forms? Let me know, because I'd like to do
something that with a database I'm working on. Thanks.


Yes, you can open the form in dialog mode:

DoCmd.OpenForm "frmMyDialog", WindowMode:=acDialog

Then your code will halt and wait until the form is either closed or hidden
(by setting its Visible property to False).
 
D

DoveArrow

Yes, you can open the form in dialog mode:

DoCmd.OpenForm "frmMyDialog", WindowMode:=acDialog

Then your code will halt and wait until the form is either closed or hidden
(by setting its Visible property to False).

That's pretty cool, but I don't want it to act like a dialogue box. I
just want to make it so that the user can't click on anything else
while the form is open.

If it helps, I'm running something that works kind've like a Wizard-
where the person enters a piece of information into a box, clicks
next, and a new form pops up requesting the next piece of information.
The reason I don't want someone to be able to click on anything else
when this process is running is because there's a primary form, that
each of these forms pulls an ID number from, and I don't want someone
to accidentally change information on that form while the Wizard is
running. I hope that makes a little more sense.
 
R

Rick Brandt

DoveArrow said:
That's pretty cool, but I don't want it to act like a dialogue box. I
just want to make it so that the user can't click on anything else
while the form is open.

Set its Modal property to Yes.
 
D

DoveArrow

Set its Modal property to Yes.

I'm having the same problem that I encountered with your first method.
Here's the problem in a nutshell: Let's say that I have three forms-
Form1, Form2, and Form3. On Form2, the Modal Property is set to 'Yes.'
On Form1, I have a button that opens Form2, using the following code:

Private Sub OpenForm2_Click()
DoCmd.OpenForm "Form1"
End Sub

Form2 acts basically like a filter for Form3. After the user selects
an ID from a list box on Form2, they click a button, marked OK, and it
runs the following code:

Private Sub OK_Click()
Dim str As String

str = Me.ID

On Error GoTo Err_OK_Click

DoCmd.OpenForm "Form3"
Forms!Form3!ID.SetFocus
DoCmd.FindRecord str
DoCmd.Close acForm, "Form2"

Exit_OK_Click:
Exit Sub

Err_OK_Click:
MsgBox Err.Description
GoTo Exit_OK_Click

End Sub

Now normally, this has worked just fine. However, when this code is
run with the Modal Property of Form2 set to Yes, it opens Form3 behind
Form1.

Now I've tried putting in the following line of code at the end of the
sequence to correct for this issue and it works fine for the most
part:

Forms!Form3.SetFocus

However, on Form3, I have a button that can be used to open Form2, in
case the user decides to select a different advisor. If I click on
this button, I get an error message that says "A macro set to one of
the current field's properties failed because of an error in a
FindRecord action argument." If I take this line of code back out of
Form2, though, the button works just fine from Form3.

It's funny how complicated something that seems relatively simple can
ultimately turn out to be. :)
 
Top