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

making a command button on a form append a record ... 1

Status
Not open for further replies.

sply

MIS
May 31, 2001
5
GB
Hi all

I'm new to tek-tips and new to access, but I have a history of pascal, delphi, c++, oracle, paradox and so on. I'm trying to help my girlfriend with her ONC by helping her with a project that has to be done in access.

What I want to do is make a command button on a form append a record to a table based on returned dataset from a query on which the form is based!!! Does that make sense?
The app is a video shop rental thingy. I have a member details table and a film details table and a rentals table which has a 1 2 M rel to the other two. the form is based on a query which requests the member number and the video number and then displays the result. I want the OK command button to then insert this dataset into the rentals table, but I'm not having a lot of joy at the moment.
Any help greatly appreciated.

My Regards

Sply
 
OK, I assume you have the data you want to add, based on your query, and just need to know how to add the record to your RENTALS table.

Code:
dim dbs as database, rst as recordset
set dbs = CurrentDb()
set rst = dbs.openrecordset("RENTALS")

rst.AddNew
rst![Field1] = Data1
rst![Field2] = Data2
etc, etc, etc..
Code:
rst.Update
rst.Close

set rst = Nothing
set dbs = Nothing

Let me know if that isn't what you're looking for
 
Hi jflachman

just tried it - poifect

thanks a lot.

I also need to update records in the recordset returned from the query. Is this possible with the same constructs?

My Regards

Sply
 
It is possible, do you have a recordset object returned from the query? If so, let's call it rstQuery

You would use the same structure
Code:
rstQuery![Field1] = ...

To move between records, you would use constructs such as:
Code:
rstQuery.MoveFirst
rstQuery.MoveLast
rstQuery.MoveNext
rstQueyr.MovePrevious

Anything else?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top