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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to & from tables

Status
Not open for further replies.

lous

Technical User
Mar 8, 2002
53
US
I've asked this before, but gotten very little response. I hope I can do better here.

I have an Access database that has two tables. On one form, when someone clicks a button, it should add 1 to the number currently in that field and then save that number to another table so that when the form is opened again, that number shows up -- and is reused for each new record created until the person clicks that button again.

But I have the problem of not knowing how to read and write from the other table in the database. Can anyone help me out?? I've been trying to figure it out for a few days now with no luck. Is this even possible?

Any help would be much appreciated. If you need more information, just let me know.
 
Here's a method:

1) when the button is clicked, update the number in the table:

' TableName is the name of the table containing the numeric
' value to be used elsewhere
' CurrentValue is the field name.

sub MyButton_OnClick
dim MyRst as recordset
set myrst = currentdb.openrecordset("TableName")
myrst.edit
myrst("currentValue") = nz(MyRst("CurrentValue"), 0) + 1
myrst.update
myrst.close
set myrst = nothing
end sub

'then, in the form before update

private sub Form_BeforeUpdate
dim MyRst as recordset
set myrst = currentdb.openrecordset("TableName")
me![NumericValue] = myrst("currentValue")
myrst.close
set myrst = nothing
end sub

HTH
 
Excellent. It works perfectly! Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top