Inster or update in one query

stone28

Registered User.
Local time
Today, 22:38
Joined
Aug 27, 2009
Messages
58
Hi guys,

I got help from here with the query below and it works like a dream...

However now I would like something like that but for two unique keys... Is it possible...

the table looks like this:
ID movie_id user_id comment

So I would like to enter new entry but if there is already comment for that movie from that particular user then update. Is it possible?

Thanks

INSERT INTO tbl_movies_genre
(tbl_movies_genre.movie_id, tbl_movies_genre.movie_genre)
VALUES ('movieID', 'movieGenre')
ON DUPLICATE KEY UPDATE tbl_movies_genre.movie_genre ='movieGenre ';
 
What I would do is use a Dlookup om the comment to see if it exist and based on that test, do either an Insert or an Update.

Code:
If Nz(Dlookup("comment", "tbl_movies_Genre", ("[user_id]) =" & [[COLOR=red]someparameter[/COLOR]] AND "[movie_id] =" & [[COLOR=red]someparameter[/COLOR]])),"") ="" Then
 ..Do the Insert
 
 Else
 .. do the Update
 
End If

Replace the bit's marked in red with the correct parameter.

Edit: This could be done from a FormModule, perhaps some click_event of a button.
Hope this helps.

JR
 
As I am using it from WEB access it has to be pure query. Is it not doable in one query?
 

Users who are viewing this thread

Back
Top Bottom