By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,761 Members | 1,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,761 IT Pros & Developers. It's quick & easy.

Extra data added to table

P: 1
The problem that I am having is adding a new record to a table. Everytime I close the form, it adds a blank field to the table. How do I stop that from happening? The following is the code that is being used currently. Any help or comments on this issue is greatly appreciated.



Expand|Select|Wrap|Line Numbers
  1. Private Sub Command27_Click()
  2. Dim rst As ADODB.Recordset
  3. If IsNull(Me.name1) Or _IsNull(Me.Year) Or _IsNull(Me.cardnum) Or _IsNull(Me.manuf) Or _IsNull(Me.Condition) Then
  4.  
  5. MsgBox "These fields need data"
  6. Else
  7. Set rst = New ADODB.Recordset
  8. With rst
  9. .ActiveConnection = CurrentProject.Connection
  10. .CursorType = adOpenKeyset
  11. .LockType = adLockOptimistic
  12. .Open "tblhave"
  13. .AddNew
  14. !Year = Me.Year
  15. !card = Me.cardnum
  16. !Name = Me.name1
  17. !Manufacturer = Me.manuf
  18. !Condition = Me.Condition
  19. !need = Me.test
  20. !price = Me.price
  21. .Update
  22.  
  23. End With
  24. End If
  25. Me.Year = Null
  26. Me.cardnum = Null
  27. Me.name1 = Null
  28. Me.price = Null
  29. End Sub
May 21 '07 #1
Share this Question
Share on Google+
2 Replies

NeoPa
Expert Mod 15k+
P: 31,770
Try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.     ' Undo the current record
  3.     DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
  4. End Sub
Jun 2 '07 #2

MSeda
Expert 100+
P: 159
Are the controls on the form bound to the forms recordsource. If they are then that may be the cause.
When the user opens the form and begins to enter data the data is entered directly into the table via the bound control. the click event of the command button then enters the data into the table again programatically and also sets all of the bound controls on the form to null, thus creating the blank record.
If your form and controls are bound there is no reason to insert the data programmatically.
Jun 2 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.