Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculated Field

Status
Not open for further replies.

d1004

Programmer
May 9, 2002
78
0
0
US
Hi,
I know that the general rule is not to store the calculated field. But let suppose that in my situation, I have to store it. I create a query to create my form with two calculated field in it, which will populated onto the form when the users enter the data. However, after
the users are finish with that record, the calculated fields are not store into the table while the other fields get stored. Is there a way that I can store it into my database.
Thank you!!!!!!!!!
-d1004
 
Not sure if this idea will help... May be changing the query to a 'make-table' query - or use a make table query to do the job some how. Might have to experiment.
 

It's not a "general rule".

It's one of The Rules of Normalization. Gus Brunston [glasses] An old PICKer, using Access2000.
 
This is usually true but in some cases it may be necessary to store the calculation such as in a case where the values used in the calculation are updated.

Try something like this:

(click event on close form)

Dim rs As Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("yourTable")

rs.AddNew
rs!yourFieldInTable = Me.yourField

rs.Update

DoCmd.Close
Exit Sub
 
Hi again,
I'm pretty new at this, so I don't know anything about VBA.
This is what I have for my code in my event procedure based from what I know from ASP:

Private Sub txtSave_Click()
Dim rs As Recordset

Set rs = New ADODB.Recordset
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Open "tblTransactions"

rs![ContractDate] = Me![ContractDate]
rs![USDollars] = Me![USDollars]

rs.Update
rs.Close
End Sub

However I have some question, do I need to create
a Connection or anything like that. And what is
Set db = Currentdb.
I know macros, can I use that instead?

please help!!! Thank you!!!!!
 
Okay,
I try a different method, instead of using ADO, I used
DAO. So here are my codes:
Private Sub txtSave_Click()
Dim rs As DAO.Recordset, dbs As Database

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("SELECT * FROM tblTransactions WHERE [ID] = '" & _
Me![ID] & "'", dbOpenDynaset)

With rs
.Edit
![ContractDate] = Me![ContractDate]
![USDollars] = Me![USDollars]
.Update
End With

rs.Close

End Sub

It doesn't work either.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top