A couple of (hopefully) quick questions

C

Claire

Hi everyone-
I'm trying to automate with forms and am running into two problems I feel
like should be easy fixes, but are proving otherwise.

1) I have a button on a form that I would like to have open a second form
that you don't actually see, which in turn opens a third form that you do
see. (The second form runs a query off of information from the first form,
and fills the defaults for form three that is tied to a separate table.) I
tried opening the second form in Dialog Mode, and wanted to set its property
to invisible, but I can't find the code to do that. I'm looking for help
making the second form invisible when it's opened, or another solution to
this problem.

2) The third form of the chain has a button to cancel. When this is
clicked I would like the form to close and the data to NOT be entered (or to
be deleted) from the table. I've played around with various undo commands
and using DAO to see if a record exists, and though it can find a record and
delete it, this seems like it happens before the form is actually closed and
the record is added.

Thanks for any help you can offer!
~Claire


Code for 2), using DAO to delete the entry:
Private Sub Cancel_Click()
'Look if CS was created in table, if so, delete.
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Tests", dbOpenTable)
rst.Index = "PrimaryKey"
rst.Seek "=", Me.CS

DoCmd.Close

If Not rst.NoMatch Then
rst.Delete
MsgBox "found test and will delete it"
DoCmd.Close
Else
MsgBox "Didn't delete anything"
DoCmd.Close
End If

End Sub
 
D

Dirk Goldgar

Claire said:
Hi everyone-
I'm trying to automate with forms and am running into two problems I feel
like should be easy fixes, but are proving otherwise.

1) I have a button on a form that I would like to have open a second form
that you don't actually see, which in turn opens a third form that you do
see. (The second form runs a query off of information from the first
form,
and fills the defaults for form three that is tied to a separate table.)
I
tried opening the second form in Dialog Mode, and wanted to set its
property
to invisible, but I can't find the code to do that. I'm looking for help
making the second form invisible when it's opened, or another solution to
this problem.

If the second form is hidden, it can't be in dialog mode. I'm not sure
whether you need dialog mode for some reason. To open the form hidden, you
can use the WindowMode argument of the DoCmd.OpenForm method:

DoCmd.OpenForm "Form2", WindowMode:=acHidden

It isn't at all clear to me why you need to open an intermediary form just
run a query to get values for the third form. I would think you could do
that either in the first form (before opening the third form) or in the
third form itself, in its Open or Load event.
2) The third form of the chain has a button to cancel. When this is
clicked I would like the form to close and the data to NOT be entered (or
to
be deleted) from the table. I've played around with various undo commands
and using DAO to see if a record exists, and though it can find a record
and
delete it, this seems like it happens before the form is actually closed
and
the record is added.

If the data has not yet been saved, you can just undo the form before
closing it:

If Me.Dirty Then Me.Undo
DoCmd.Close acForm, Me.Name, acSaveNo

If the record has already been saved, though, you do have to explicitly
delete it. If you are *sure* that the current record should be deleted if
it has been saved, and undone if it hasn't been saved, you can write this:

If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then Me.Recordset.Delete
DoCmd.Close acForm, Me.Name, acSaveNo
 

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