add record

G

golan

hello; i have command with click event that add a new record.
the recoed is add but when i want to add the new the to the new record the
cursor
is on the old record .
how i make it that the cursor is always gone to next\new record.
thanks
 
J

John W. Vinson/MVP

hello; i have command with click event that add a new record.
the recoed is add but when i want to add the new the to the new record the
cursor
is on the old record .
how i make it that the cursor is always gone to next\new record.
thanks

I'm not sure I understand. What do you mean by "add the new the to the
new record"???

Please post your code, and indicate what is happening when you run it.
 
G

golan

Private Sub CmdDone_Click()

frmpaid = True

Dim payment As DAO.Recordset ' Recordset declaration for payment,
' A recordset is a
data structure that consists of a group of database records,
' and can either
come from a base table or as the result of a query to the table


Set payment = CurrentDb.OpenRecordset("tblpayment", dbOpenDynaset) '
setting the recordset variable to the "tblpayment" table.

payment.Edit
' DBopenDynaset means
that we can wrtie to this table from this code.
payment.Fields!paid.Value = frmpaid
payment.AddNew
payment.Update
payment.Close

frmrenter = Null
frmasset = Null
frmpaid = no

End Sub

its add new record. if i have one record and i want to add the second its
add the second but the cursor is in record number one and i cant to enter a
new data
 
J

John W. Vinson/MVP

Private Sub CmdDone_Click()

frmpaid = True

Dim payment As DAO.Recordset ' Recordset declaration for payment,
' A recordset is a
data structure that consists of a group of database records,
' and can either
come from a base table or as the result of a query to the table


Set payment = CurrentDb.OpenRecordset("tblpayment", dbOpenDynaset) '
setting the recordset variable to the "tblpayment" table.

payment.Edit
' DBopenDynaset means
that we can wrtie to this table from this code.
payment.Fields!paid.Value = frmpaid
payment.AddNew

The two lines above need to be switched. If I understand the problem
correctly, you are trying to add a new record and set its Paid field
to the value from frmpaid (True).

If so you need to *first* AddNew (to move to the new record, blank and
empty); and only *then* set the value of the field in the recordset.
 
G

golan

sorry that i annoying u.
in load form i add the record

Private Sub Form_Load()
Dim payment As DAO.Recordset

Set payment = CurrentDb.OpenRecordset("tblpayment", dbOpenDynaset)
payment.AddNew
payment.Update
end sub

its done well but new i want to enter the data to this raw and its go to
last rew
thanks
 
J

John W. Vinson/MVP

its done well but new i want to enter the data to this raw and its go to
last rew

You're not annoying me at all - I think we're having some difficulty
communicating, is all.

A few questions:

1. Why are you using VBA and recordsets to add records to your table?
A Bound Form does so with no code at all. I am sure you have a reason
but I do not know what it is. There may be a better way to do the task
that you want.

2. If you want to add data to the record currently selected on the
form, it is best to do so using the Form. Simply set the value of a
bound textbox on the form to the value that you want, and then give a
command like

DoCmd.GoToRecord acDataForm, Me.Name, acNewRecord

3. If you need to update a record using a recordset, and then move to
the new record in that recordset, then you need two Move steps:

Private Sub Form_Load()
Dim payment As DAO.Recordset

Set payment = CurrentDb.OpenRecordset("tblpayment", dbOpenDynaset) <do
something to find the record which you want to update - I do not know
what record that is>
Payment!fieldname = Me!controlname
' then update the record
payment.Update
' then move to the new record
payment.AddNew
end sub

Note that moving from record to record in the Recordset will do
ABSOLUTELY NOTHING on the form; the recordset and the form are
independent.
 
G

golan

hello john, i have 4 tables : renters,contracts,payments, assets.
in the form payment i have 2 comboboxes : 1.renter from table renters and
2. asset from contracts. the data from this form go to table payment .
if i choose renter ,in combobox "2" i can choose only assets of the renter
in combobox"1" this combobox take the data from a query.
the reason i need to use recordset is that i need in realtime to enter the
data (renter) to a feild in table payment for the query.
finally i need to click in chackbox to ok. if i want to add new record i
click command button.
 

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