Stop a Record form Inserting

E

Eka1618

Hello,

I am trying to figure out how to eliminate a record from inserting into a
table if the user chooses to close a form by pressing the close btn int he
control box.

I have validation rules set. If someone starts to enter data and decides not
to use this form for whatever reason, I want them to have the ability to
close the form without seeing a message and without the data they entered
stored in a table. Since I have the val. rules set, it does everything I want
except it shows messages...

Another thing I want to point out is that if a user fills out all the data,
and chooses btnSend, this will cause the close event to occur in the form as
well. I feel like I am in a dilemma on what I should do. If the user hits
btnSend, I want their data to stay in tables. If they hit the close btn, I
want their data to dissapear.

Does anyone know what I should do? I could disable the close button all
together and make my own close button I suppose... If you have a suggestion,
Please let me know. Thank You!
 
G

GregB

Hello,

I am trying to figure out how to eliminate a record from inserting into a
table if the user chooses to close a form by pressing the close btn int he
control box.

I have validation rules set. If someone starts to enter data and decides not
to use this form for whatever reason, I want them to have the ability to
close the form without seeing a message and without the data they entered
stored in a table. Since I have the val. rules set, it does everything I want
except it shows messages...

Another thing I want to point out is that if a user fills out all the data,
and chooses btnSend, this will cause the close event to occur in the formas
well. I feel like I am in a dilemma on what I should do. If the user hits
btnSend, I want their data to stay in tables. If they hit the close btn, I
want their data to dissapear.

Does anyone know what I should do? I could disable the close button all
together and make my own close button I suppose... If you have a suggestion,
Please let me know. Thank You!

Depends on what you are doing to process your query. The concept of a
database transaction may be helpful to you (look it up in wikipedia)
as that allows the rollback of a query or series of queries before the
tranaction is completed.

Hope this helps,
GregB
 
E

Eka1618

Greg,

The control source of this form is not a query, its a table; so I suppose
the query would be: Select * from tblRequest;
The Control source for all the subforms on this particular form are tables
as well.

I have been working on this for a while now and think I am still at where a
was a while ago. The record does not enter if the parent form is not filled
out all the way. Unfortunately, it is not allowing me to say
:docmd.setwarnings = false/true in the spot where I'd like it to be:

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_err
Dim strValid As String

strValid = CheckFormValues(Me)

If strValid <> vbNullString Then
MsgBox "All fields must be filled before Continuing. If exiting,
all data will be lost."
'*******DoCmd.SetWarnings = false**********
Cancel = True
'*******DoCmd.SetWarnings = True**********
End If

BeforeUpdate_Exit:
Exit Sub

BeforeUpdate_err:
MsgBox Error$
Resume BeforeUpdate_Exit
End Sub


Also, let's say that a person clicks close and they did not fill out any
information on the subforms, I do not want to save information then as well.
I could always make public variables (boolean perhaps) that are used as a
flag to determine whether or not data in subforms has been entered...

I am not sure what to do. In addition to this problem, I have another
problem regarding the function CheckFormValue() that you see in the above
script. The function works as it should, but I am having difficulty as to
where I should be calling the function. i call this function in a few
different places, but generally, i call it in the BeforeUpdate event of my
forms because if a user already started to enter data, it checks to make sure
they fill everything in. I know this function is causing problems when i try
to close a form... I have some msgbox statement alert the person, so maybe I
could get rid of them...

Very confused....
 
E

Eka1618

Well I think I Fixed it... a little...

I cleaned up my code a little bit and that may have solved my problem why
certain events were occuring when they did.

I still would like to find a way to use: DoCmd.SetWarnings = false

I would prefer if the users did not see this message. I am assuming that the
warning pops up durring the BeforeUpdate event, but if I am wrong, at what
point does this warning occur?

If you have any ideas, please let me know, Thank You!
 

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