Don't save record

G

Guest

I have a form (frmContacts) in which users enter home visit data pertaining
to specific clients. On this form is a button which opens a linked form
(frmSummary) used for entering a monthly text summary of those visits.
Sometimes users will add data in frmContacts and then continue on to
frmSummary. Sometimes however, they will simply open frmContacts, choose a
client from a combo box, and then continue on to frmSummary, without adding
any other data to frmContacts. This all works fine except that even when the
user doesn't add any other data to frmContacts, it still saves a record. I
understand why this happens, but I need it to NOT save the record if certain
conditions are not met, for example, if no date is entered or if no time is
specified. I'm pretty new to using code, but I'm learning quickly, so I
don't think I'll be completely lost if it's necessary to use it.

Any help is appreciated!
 
P

pietlinden

If all you need are some fields to be required, why not just set that
up at at table level? Then the validation will fail before the user
can go anywhere else.
 
G

Guest

In the BeforeUpdate event of the form try something like


If IsNull(Me.[TextBoxName) Then
Me.Undo ' will undo the changes
End If

If needed you can prompt a message to the user if he/she want to continue
before closing the form
 
G

Guest

Thanks for the suggestion, unfortunately neither your solution, nor the one
before yours will work for me. The solution you recommended erases the data
before it can be passed into the linked form, I need it to pass the
ClientCaseInfoID number on, but then delete the record once both forms are
closed.

Ofer Cohen said:
In the BeforeUpdate event of the form try something like


If IsNull(Me.[TextBoxName) Then
Me.Undo ' will undo the changes
End If

If needed you can prompt a message to the user if he/she want to continue
before closing the form

--
Good Luck
BS"D


Tara said:
I have a form (frmContacts) in which users enter home visit data pertaining
to specific clients. On this form is a button which opens a linked form
(frmSummary) used for entering a monthly text summary of those visits.
Sometimes users will add data in frmContacts and then continue on to
frmSummary. Sometimes however, they will simply open frmContacts, choose a
client from a combo box, and then continue on to frmSummary, without adding
any other data to frmContacts. This all works fine except that even when the
user doesn't add any other data to frmContacts, it still saves a record. I
understand why this happens, but I need it to NOT save the record if certain
conditions are not met, for example, if no date is entered or if no time is
specified. I'm pretty new to using code, but I'm learning quickly, so I
don't think I'll be completely lost if it's necessary to use it.

Any help is appreciated!
 
G

Guest

Hi Tara,
you can save the value of the combo box in a global variable before the undo
command and then use this global variable to open the second form

You've to declare the GlobalVariable in a Module in this way
Global NameOfTheGlobalVariable as the type of ClientCaseInfoId

If IsNull(Me.[TextBoxName) Then
NameOfTheGlobalVariable=ClientCaseInfoID
Me.Undo ' will undo the changes
else
NameOfTheGlobalVariable=ClientCaseInfoID
End If
Now use NameOfTheGlobalVariable to open (frmSummary)

HTH Paolo



Tara said:
Thanks for the suggestion, unfortunately neither your solution, nor the one
before yours will work for me. The solution you recommended erases the data
before it can be passed into the linked form, I need it to pass the
ClientCaseInfoID number on, but then delete the record once both forms are
closed.

Ofer Cohen said:
In the BeforeUpdate event of the form try something like


If IsNull(Me.[TextBoxName) Then
Me.Undo ' will undo the changes
End If

If needed you can prompt a message to the user if he/she want to continue
before closing the form

--
Good Luck
BS"D


Tara said:
I have a form (frmContacts) in which users enter home visit data pertaining
to specific clients. On this form is a button which opens a linked form
(frmSummary) used for entering a monthly text summary of those visits.
Sometimes users will add data in frmContacts and then continue on to
frmSummary. Sometimes however, they will simply open frmContacts, choose a
client from a combo box, and then continue on to frmSummary, without adding
any other data to frmContacts. This all works fine except that even when the
user doesn't add any other data to frmContacts, it still saves a record. I
understand why this happens, but I need it to NOT save the record if certain
conditions are not met, for example, if no date is entered or if no time is
specified. I'm pretty new to using code, but I'm learning quickly, so I
don't think I'll be completely lost if it's necessary to use it.

Any help is appreciated!
 

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