CurrentRecord or Bookmark?

  • Thread starter lad5ko via AccessMonster.com
  • Start date
L

lad5ko via AccessMonster.com

Hi,
I need multiply fields [Price] and [Amount] and result write into field
[Result1] into current Record (opened in form). My code multiplies always
[Price] and [Amount] from first record of Tab1 and writes result also into
first record of Tab1, not into current record that I can see in my form.

Any help will be appreciated.

Thanks in advance.

L.P.

Private Sub Button1_Click()
Dim MyDb As DAO.Database, MyTable As DAO.Recordset
Dim Result1 As Double

Set MyDb = CurrentDb()
Set MyTable = MyDb.OpenRecordset("Tab1", dbOpenDynaset)

Result1 = MyTable![Price] * MyTable![Amount]
MyTable.Edit
MyTable![FieldA] = Result1
MyTable.Update

MyTable.Close
MyDb.Close
End Sub
 
B

Baz

That's because you are opening and updating a recordset which is completely
independent of the form. Nowhere do you indicate which record is to be
updated, so the first record in the recordset gets it.

Anyway, the whole thing would appear to be a mistake: it is rarely
appropriate to store derived data in your database. Why not simply put a
text box on your form and set it's control source as follows:

= [Price] * [Amount]
 
L

lad5ko via AccessMonster.com

Thanks, it works.
That's because you are opening and updating a recordset which is completely
independent of the form. Nowhere do you indicate which record is to be
updated, so the first record in the recordset gets it.

Anyway, the whole thing would appear to be a mistake: it is rarely
appropriate to store derived data in your database. Why not simply put a
text box on your form and set it's control source as follows:

= [Price] * [Amount]
Hi,
I need multiply fields [Price] and [Amount] and result write into field
[quoted text clipped - 23 lines]
MyDb.Close
End Sub
 

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