Make record only on "ADD" button

F

Fred

Hi.. I'm having a problem with my form.. It has 3 textboxs connected to a
table.. On the form options "data entry" = yes..
The problem i have it's that i made this form to add those 3 field to a
table and i only want to add them when the user clicks the "ADD" button.. but
what is happening is that automaticly when the user just clicks one of those
3 textboxs, not even needs to write something, if i close it on the X (its a
popup form) or if i click the "CANCEL" button when i check the table a new
registry was made.. I dont want that.. i only want the record to be made when
the user clicks the "ADD" button with this code:

Private Sub Command1_Click()
If IsNull(DLookup("Park", "Query_park")) = False Then
MsgBox "Park already created!"
Else
If IsNull(parkname) = True Or IsNull(area) = True Or IsNull(Panel) = True Then
MsgBox "ERROR:Fill every field"
Else
If Me.Dirty Then Me.Dirty = False
DoCmd.RunCommand acCmdRecordsGoToNew
MsgBox "Parque adicionado!"
DoCmd.Close
DoCmd.OpenForm "Form2"
End If
End If
End Sub

How can i solve this problem??
I cant have blank records or Wrong records on the table connected to this
form because on other form i have a combobox looking up for the "parkname"
column of the table..

Thanks
Nuno
 
J

Jeff Boyce

By design, when you leave (close) an Access form that is "bound" to a table,
the changes you've made are saved.

If you are using a form with "data entry = yes", then the record you've
added is saved.

If you wish not to save a record, and you want to ensure that all fields are
filled, you could add code to a BeforeUpdate event that validates first and
uses Undo to remove the entries if validation fails.

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 

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