Z-Man said:
I am Using Left outer join to join the tables. The inner table may
or may not have a record for that key. I want to give user option to
update the info on inner table. How can I check to decide upfront if
I need an Update or insert routine.
Thanks a lot.
You could go about this several different ways, depending on exactly
what you want to achieve. Are you intending to operate on at most one
matching record from the "inner" table? Do you want to insert a record
if it doesn't exist, and update it if it does exist, without user
confirmation? Or do you want to find out if it exists, then ask for
confirmation of the update if it exists? Can you identify by key a
specific record to be updated, in the case that at least one "inner"
record exists?
You could ...
A. Use DLookup first to find out if the record exists. Then, if it
doesn't, add it; if it does, ask for confirmation and then update it.
B. Open a recordset on the query. Determine by inspection of the field
values in the recordset whether the record exists or not. If it
doesn't, just update the appropriate fields in the recordset; if it
does , ask for confirmation and then update the recordset.
C. If the record to be added would have a unique key, then you could use
the DAO Execute method to insert the record, determine if the insert
failed (db.RecordsAffected = 0) and then decide whether to run an update
query instead.
I suppose other approaches are also possible, but you haven't given
quite enough information about what you're trying to do.