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!

adding value to access db 2

Status
Not open for further replies.

cspm2003

Programmer
Nov 24, 2004
78
DE
Hi,

I have a access database called "db1". in this database, theres a table called "database"

this table has to columns, one called ID, and another one called Name

I want to append a new id and name under the last entry in this database using vb6. heres what I tryed:

Code:
Set DB = DBEngine.Workspaces(0).OpenDatabase("D:\db1.mdb")
Set rs = DB.OpenRecordset("database")

rs.execute "INSERT INTO database(ID, Name) VALUES (2, Vanessa)"

but that doesnt work :-(

what am I doing wrong?
 
You need to put the values in single quotes. Unless ID is a numeric field, single quotes aren't used for numeric fields. Just put them round Vanessa.

Harleyquinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
That along with executing it on the DB object and not the rs object.

DB.EXECUTE "INSERT INTO database (ID, Name) VALUE (2, 'Vanessa')"
 
Good call bjd4jc, missed that one [sad]

Harleyquinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Hi, thx for the replys. ID isnt a numeric field.

I've tryed

DB.EXECUTE "INSERT INTO database (ID, Name) VALUE (2, 'Vanessa')"

but that doesnt seam to work. I get an error message that there is a syntax error in the insert instruction
 
It could be that Database is a reserved word. Try putting square brackets around it.

Code:
DB.EXECUTE "INSERT INTO [database] (ID, Name) VALUE (2, 'Vanessa')"

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
And put the 2 in single quotes as it's not a numeric field.

Harleyquinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
yay, with the sqare brackets it works. Im gona rename the "database" to something else


ups, I did copy and past from my previous posts, thats why no single quotes

thx for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top