Re: updating table from a text box
- From: "mcarlyle via AccessMonster.com" <u6592@uwe>
- Date: Wed, 24 Sep 2008 17:32:08 GMT
ok I tried your way and I am getting an error... (because I had to add a
primary key)
Now i get an error saying "didn't add 1 record(s) to the table due to key
violations."
I added a primary key called noteid. [Id] that was already there is a
reference to the primary key of another table and has duplicates in notes, so
after upsizing to sql I needed a primary key and added it.
Since then I have the error listed above. Prior to adding the key, both
yours and my codes worked, but since yours is obviously better I chose to use
it.
Douglas J. Steele wrote:
That's surprising: it shouldn't work!
The Jet engine has no idea where to find the values [notes] and [ID]. Based
on your previous post, I'm assuming they're the names of controls on your
form. I'll further assume that notes is a text field, and that ID is a
numeric field. Another possible complication is that the notes field might
contain apostrophes or double quotes. That means your SQL should be:
"INSERT INTO notes ([notes], [id]) " & _
"VALUES ('" & Replace(Me![notes], "'", "''") & "', " & _
Me![ID] & ")"
Exagerated for clarity, that middle row is
"VALUES ( ' " & Replace(Me![notes], " ' ", " ' ' ") & " ', " & _
And in my opinion, you're better off using the Execute method of the DAO
Database object. That avoids needing to futz with SetWarnings, plus you can
have it raise a trappable error if something goes wrong:
CurrentDb.Execute "INSERT INTO notes ([notes], [id]) " & _
"VALUES ('" & Replace(Me![notes], "'", "''") & "', " & _
Me![ID] & ")", dbFailOnError
I found this and it works instantly...[quoted text clipped - 5 lines]
I turned the warnings off because they popped up a box each time.
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200809/1
.
- Follow-Ups:
- Re: updating table from a text box
- From: mcarlyle via AccessMonster.com
- Re: updating table from a text box
- References:
- updating table from a text box
- From: mcarlyle via AccessMonster.com
- Re: updating table from a text box
- From: mcarlyle via AccessMonster.com
- Re: updating table from a text box
- From: mcarlyle via AccessMonster.com
- Re: updating table from a text box
- From: Douglas J. Steele
- updating table from a text box
- Prev by Date: Re: Is there a way?
- Next by Date: Help relinking tables
- Previous by thread: Re: updating table from a text box
- Next by thread: Re: updating table from a text box
- Index(es):
Relevant Pages
|