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!

'Move data from one table to another' Button? 1

Status
Not open for further replies.

PaulChilds

Technical User
May 21, 2002
195
Hi,

I have two forms (based on two tables). One for existing clients and one for prospective clients.

When a prospective client signs up to the company, I need a button or somnething that deletes the record from the Prospective CLients tables/form and moves it over to the existing clients table.

Any ideas?

The tables/forms are called: Clients & Prospective Clients.

I'd appreciate some help on this one!

Cheers.

PC
 
Hi

First Question, why have two tables?, why not just have one table, with an indicator in each row for Prospective/Actual, then you would not need to copy the record, but simply the indicator

but to answer yor question

In the button on click event somethin like:

DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tblActual SELECT * FROM tblProspect WHERE Id = " & Me.Id & ";"
DoCmd.RunSQL "DELETE FROM tblProspect WHERE Id = " & Me.Id & ";"
DoCmd.SetWarnings True

You need to adjust the table names, and the key field name, also if you key field is a string you need ..WHERE Id = '" & Me.Id & "';"

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi

[Prospective Clients]

and do not use embedded spaces in table names or column names, or control names in future (Joke) Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
'Identifier' is the primary key field in both tables:

DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tblClients SELECT * FROM tbl[Prospective Clients] WHERE Id = '" & Me.Identifier & "';"
DoCmd.RunSQL "DELETE FROM tbl[Prospective Clients] WHERE Id = '" & Me.Identifier & "';"
DoCmd.SetWarnings True
 
Hi

Assuming the table name is "tblProspective Clients" not "Prospective Clients"

DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tblClients SELECT * FROM [tblProspective Clients] WHERE Id = '" & Me.Identifier & "';"
DoCmd.RunSQL "DELETE FROM [tblProspective Clients] WHERE Id = '" & Me.Identifier & "';"
DoCmd.SetWarnings True Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi

Ok, so no error means the SQL 'reads' OK, but maybe it cannot fine anything with Id to match the id you gave it.

Suggest you put abreakpoint on the first d0cmd.runsql

Run

Whenit stops examine the value of Me.Identifier and make sure there is a matching key in Table [Prospective Clients] Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi

Is Id the name of the column in the tables Clients and [Prospective Clients] which uniquely identifies the client?

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi

Well that is your problem you need:

DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tblClients SELECT * FROM [Prospective Clients] WHERE Identifier = '" & Me.Identifier & "';"
DoCmd.RunSQL "DELETE FROM [Prospective Clients] WHERE Identifier = '" & Me.Identifier & "';"
DoCmd.SetWarnings True

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top