Access copy row querry

I have a table called "controls" and "roles". They are the exact same structure.
Now i need to copy the values in the row of table "roles" (with username "default") to the "controls" table with a new username im getting from the parameter. Any ideas how to do this in 1 access querry ?!


PARAMETERS [@username] Text ( 50 );
DECLARE  [@top] text (255), [@left] Text  (255),[@middle] Text (255), [@right] Text (255),[@bottom] Text (255);

SELECT  [@top] = Roles.[top], [@left]=Roles.[left], [@middle]=Roles.[middle], [@right]=Roles.[right], [@bottom]=Roles.[Bottom]
FROM Roles
WHERE Roles.Username = "default"

INSERT INTO controls Values  SET controls.username = [@username], controls.[top] = [@top], controls.[left] = [@left], controls.middle = [@middle], controls.[right] = [@right], controls.bottom = [@bottom]
LVL 4
zinnoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

morpheus30Commented:
INSERT INTO Controls (Top, Middle, Right, Bottom, UserName) SELECT Top, Middle, Right, Bottom, UserName, [Enter UserName] FROM Roles
0
morpheus30Commented:
Sorry, I forgot the where statement

INSERT INTO Controls (Top, Middle, Right, Bottom, UserName)
SELECT Top, Middle, Right, Bottom, UserName, [Enter UserName]
FROM Roles
WHERE UserName = "default"

0
heer2351Commented:
Looks like you have a .adp, correct?

This should do the trick:

PARAMETERS [@username] Text ( 50 );
INSERT INTO controls (username, top, left, middle, right, bottom)
SELECT [@username], [top], [left], [middle], [right], [Bottom]
FROM Roles
WHERE Username = "default"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

heer2351Commented:
Sorry morpheus30 did not see your code until I posted mine, only difference that I declare the parameter first.
0
svenkarlsenCommented:
And on first given opportunity, you should change the name of your table "Controls", - it is a critical word to use for naming objects in Access, as it has explicit meaning in certain relations.

Sven
0
morpheus30Commented:
Oh dude...

I misunderstood the question: Any ideas how to do this in 1 access querry ?!

I was thinking you were trying to convert T-SQL into native Access SQL used by .mbd files.  My solution won't work if you're using an .adp file.  heer2351's solution should work for you there...

0
morpheus30Commented:
If you want to save it as a query (Stored Procedure) in your Access .adp file, you could copy and paste the following SQL statement

INSERT INTO Controls (Top, Middle, Right, Bottom, UserName)
SELECT Top, Middle, Right, Bottom, UserName, @UserName
FROM Roles
WHERE UserName = 'default'
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.