oOple.com Forums

oOple.com Forums (http://www.oople.com/forums/index.php)
-   The PlayGround (http://www.oople.com/forums/forumdisplay.php?f=45)
-   -   MS Access SQL helped needed for SQL beginner.. (http://www.oople.com/forums/showthread.php?t=23527)

chris_dono 05-05-2009 09:25 PM

Here's one way to do it:
Create a module and paste the following:

Code:


Sub CreateRecs()
DoCmd.RunSQL "INSERT INTO STAFF (STAFFID, FIRSTNAME, LASTNAME, TEAM, JOINDATE, WAGEPERHOUR, AMBID) " & _
"VALUES('S01','Steve','Carrow', 1,'14-Apr-1980', 12.54,'A01')"
DoCmd.RunSQL "INSERT INTO STAFF (STAFFID, FIRSTNAME, LASTNAME, TEAM, JOINDATE, WAGEPERHOUR, AMBID) " & _
"VALUES('S02','John','Parry', 3,'23-Mar-1999', 9.44,'A02')"
DoCmd.RunSQL "INSERT INTO STAFF (STAFFID, FIRSTNAME, LASTNAME, TEAM, JOINDATE, WAGEPERHOUR, AMBID) " & _
"VALUES('S03','Hannah','Jones', 7,'12-Dec-2006', 10.38,'A03')"
End Sub

This will insert the three rows. It will prompt you for each time it inserts.

You can't insert multiple items using the VALUES specification of the INSERT INTO syntax. For multiple items, you have to use INSERT INTO with SELECT
Code:


INSERT INTO table1 (id, value)
SELECT id, value FROM table2

is an example.

Let me know how you get on.
Cheers
Chris


All times are GMT. The time now is 03:28 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
oOple.com