Aborting from startup

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

As a form starts up, I need to check to see if a particular record is present
and terminate the form startup if not. You can't cancel any event except
load, and you can't use the related table and recordset until the Current
event. How can I terminate a form without closing the database (quit call)?
 
you CAN cancel the Open event, it's the Load event that does not have a
Cancel argument. if you're looking for a particular record, then you must
have some criteria that serves to identify that record. if the form is bound
to either a table or a query, you can run a DCount() function in the Open
event, using the identifying criteria, and cancel if the function does not
return at least one record, as

If DCount(1, "TableOrQueryName", "SomeField = somecriteria") < 1 Then
Cancel = True
End If

if you're opening this form from another form (like a menu or switchboard,
for example), suggest you check for the presence of the record *before*
opening the form, as

If DCount(1, "TableOrQueryName", "SomeField = somecriteria") > 0 Then
DoCmd.OpenForm "FormName"
End If

hth


SubXO said:
As a form starts up, I need to check to see if a particular record is present
and terminate the form startup if not. You can't cancel any event except
load, and you can't use the related table and recordset until the Current
event. How can I terminate a form without closing the database (quit
call)?
 
Doing so in the form that opens the other form requires too much knowledge
about the query/table that is in the loaded form. I just can't believe
there's no way to abort a form from within that form's code once you get past
the open event.

So, in the Current routine (after the form has progressed far enough that
its recordset object is valid), I need to see if the field contents in the
openargs is available (I know how to do that just fine) and then, if not
present in a particular field, I need to prevent the form startup. If I
'raise' an error, the error message duly comes up, but the form opens anyway.
--Dale--
 
if you take an action to open a form, and don't cancel the open event, then
the form opens, period. if you want to do something in the Current event,
then do it there, and run a Close command to close the form.

hth
 
You can't do a close action from within a form, so there is no way to stop a
form once you get past the open event. This seems so flawed I just can't
believe it. Is there no way to shut down a form from within the form code?
 
reading back over the thread, it sounds like you have figured out how to
"check to see if a particular record is present", and your issue is with
"how to close the form when that record is not present". how are you
checking for the existence of a particular record - what criteria are you
using?

hth
 
Tina, here's what I'm doing:
1) In the parent form, there is a drop-down that queries a second table,
converting the numeric foreign key to something human-understandable (e.g. a
type of music 'gospel' rather than 153) by using a combobox with the numeric,
stored item having 0 width and the human-readable text as the visible column.
2) When the user enters a value not in the list, the NotInList event fires.
I then load a form that permits the user to edit the subordinate table (e.g.
music types), with it set to add a new record with the type text set to the
value of the text entered in the combobox of the parent form.
So far, so good.
3) To make the subform load with the focus on the text-based control, the
Current event of the form scans the list of controls, finding the control
that has the field displayed from the parent's combobox form (which I pass in
OpenArgs, along with the newly-created value from the NotInList event).
4) What I wanted to be able to do was detect the situation where the control
couldn't be located for some reason and then abort the subform.
Unfortunately, there doesn't appear to be any way to programmatically
terminate a form from within that same form, as DoCmd.Close gives you an
error if you use it to close yourself.
5) What I've done to circumvent this is to enter an event loop in the parent
form (a while loop looking for the subform to place a flag-character in its
Tag field, giving control to the event processor inside the while loop).
when the loop detects this flag set, it then does a DoCmd.Close on the
suborndinate form. This is a huge klooge, but I can't see any way around it.
--Dale--
 
tina said:
reading back over the thread, it sounds like you have figured out how to
"check to see if a particular record is present", and your issue is with
"how to close the form when that record is not present". how are you
checking for the existence of a particular record - what criteria are you
using?

hth
 
well, at the start of the thread you talked about closing the form when a
particular *record* is not present; now you seem to be talking about looking
for a particular *control* on the form. if you're opening a particular form,
it seems like you'd know what controls on are the form.

i think we are probably not communicating well. since i haven't been able to
assist you, suggest you think about starting a new thread - maybe another
developer will understand what you're getting at, and be able to help you
out. good luck.
 
Back
Top