code for add button

mitraexport

New member
Local time
Tomorrow, 02:53
Joined
Nov 7, 2022
Messages
8
I have made table for my data .while doing Date enrty from form my access code makes duplicate copy of the same record while pressing adding button will anybody can help me?
Thanks in advance
 
Welcome to the forums! We are the most active Microsoft Access community on the internet by far, with posts going back over 20 years!

To get started, I highly recommend you read the post below. It contains important information for all new users to this forum.

https://www.access-programmers.co.uk/forums/threads/new-member-read-me-first.223250/

We look forward to having you around here, learning stuff and having fun!
 
without knowing your code, not possible to say.

Access will automatically insert/update a record when you leave it when going to another record or closing the form, so I suspect your add code is not required
 
I want to do, when i open form for data entry ,form should state in its status total record and prepare for accepting new record to be add. how can i do it?
 
perhaps use a dsum function in a control?

google 'access vba dsum' to find out how to use it

You are asking vague questions with no detail and since there are many ways to accomplish different things, all dependant on what you actually have, without any detail all you will get back is vague answers
 
Dear sir
very sorry ,you are right actually I should discuss in hurry ,
Now let me go through my problem. I designed table for data entry for business data and also created form to enter data. Now problem is there whenever I open form it starts form 1st record so i have to scroll all data to add new record. i want when i open the form data entry should be start form last record save and in the form when it open should be at the current record to be add and still continue till we work.
for your kind information i attech file for your view.
thanks in advance
 

Attachments

Go to last record on load of form if that is what you want to see.
I always used the * in the navigation control bar to add a new record?
 
perhaps use a dsum function in a control?

google 'access vba dsum' to find out how to use it

You are asking vague questions with no detail and since there are many ways to accomplish different things, all dependant on what you actually have, without any detail all you will get back is vague answers

Welcome aboard:)

Open your form in design view and post the entire code module. As CJ suggested, your code is causing the duplication.
Dear sir
very sorry ,you are right actually I should discuss in hurry ,
Now let me go through my problem. I designed table for data entry for business data and also created form to enter data. Now problem is there whenever I open form it starts form 1st record so i have to scroll all data to add new record. i want when i open the form data entry should be start form last record save and in the form when it open should be at the current record to be add and still continue till we work.
for your kind information i attech file for your view.
thanks in advance
 

Attachments

Where did you get that code from? You would never do that on a bound form. Replace it with one line of code
Code:
Private Sub CmdAdd_Click()
  Me.Recordset.AddNew
 '  OR use docmd
 ' DoCmd.GoToRecord , , acNewRec

'DELETE ALL AFTER
'ADD DATA FROM FORM TO TABLE
'Dim farmer As DAO.Database
'Dim rst As DAO.Recordset
'Set farmer = CurrentDb
'Set rst = farmer.OpenRecordset("farmer")
'rst.AddNew
'rst.Fields("Billdate") = Me.txtbdate.Value
'rst.Fields("billid") = Me.txtbillid.Value
'rst.Fields("farmername") = Me.txtfname
'rst.Fields("Villege") = Me.txtvillege.Value
'rst.Fields("Type") = Me.combtype.Value
'rst.Fields("Product") = Me.combproduct.Value
'rst.Fields("Bag") = Me.txtbag.Value
'rst.Fields("Weight") = Me.txtwt.Value
'rst.Fields("Rate") = Me.txtrate.Value
'rst.Fields("Buyer") = Me.txtbuyer.Value
'rst.Update
'Set rst = Nothing
'rst.Close
'Me.txtbdate.Value = ""
'Me.txtbillid.Value = ""
'Me.txtfname.Value = ""
'Me.txtvillege.Value = ""
'Me.combtype.Value = ""
'Me.combproduct.Value = ""
'Me.txtbag.Value = ""
'Me.txtwt.Value = ""
'Me.txtrate.Value = ""
'Me.txtbuyer.Value = ""
'Me.txtbdate.SetFocus
End Sub

Private Sub Form_Load()
  Me.Recordset.MoveLast
End Sub
 
I personally like to seperate data navigation, edit, and entry. Here is an idea of a more user friendly design.

Also search here on the reason not to use table lookups. Do you drop down choices in the form only.
Also do not put spaces are special characters in any object names (tables, fields, forms...) "DataEntry" not "Data Entry"
Also google Data Normalization. You probably want related tables for your data.
 

Attachments

Where did you get that code from? You would never do that on a bound form. Replace it with one line of code
Code:
Private Sub CmdAdd_Click()
  Me.Recordset.AddNew
'  OR use docmd
' DoCmd.GoToRecord , , acNewRec

'DELETE ALL AFTER
'ADD DATA FROM FORM TO TABLE
'Dim farmer As DAO.Database
'Dim rst As DAO.Recordset
'Set farmer = CurrentDb
'Set rst = farmer.OpenRecordset("farmer")
'rst.AddNew
'rst.Fields("Billdate") = Me.txtbdate.Value
'rst.Fields("billid") = Me.txtbillid.Value
'rst.Fields("farmername") = Me.txtfname
'rst.Fields("Villege") = Me.txtvillege.Value
'rst.Fields("Type") = Me.combtype.Value
'rst.Fields("Product") = Me.combproduct.Value
'rst.Fields("Bag") = Me.txtbag.Value
'rst.Fields("Weight") = Me.txtwt.Value
'rst.Fields("Rate") = Me.txtrate.Value
'rst.Fields("Buyer") = Me.txtbuyer.Value
'rst.Update
'Set rst = Nothing
'rst.Close
'Me.txtbdate.Value = ""
'Me.txtbillid.Value = ""
'Me.txtfname.Value = ""
'Me.txtvillege.Value = ""
'Me.combtype.Value = ""
'Me.combproduct.Value = ""
'Me.txtbag.Value = ""
'Me.txtwt.Value = ""
'Me.txtrate.Value = ""
'Me.txtbuyer.Value = ""
'Me.txtbdate.SetFocus
End Sub

Private Sub Form_Load()
  Me.Recordset.MoveLast
End Sub
hello sir
Wish u Happy mood
as per your suggestion your code work and I am surprised to note that only one line can do good work.
Many thanks but I want to ask that why bound control do not need such longer code?, How can i improve code writing?
thanks in advance
 
why bound control do not need such longer code?
Bound forms is the true power of Access. Access does all the work for you, that would require a huge amount of code in another application.
When you use a bound form Access takes care of adding, deleting, and editing back to the database. You do not need seperate code to do these things.
There are VERY rate times you need to build an unbound form in an Access application. Often people do it when they do not understand how Access works and they make way more effort than needed.
 

Users who are viewing this thread

Back
Top Bottom