Simple code help

F

firedog

I don't know how to code this. I have two tables the first has a yes/n
field. If a person slects yes, then I would like the rest of the field
in table 1 to be copied into table 2. I would like to use a comman
button to update table 2, or better yet I would like for the form t
update automatically, but not copy the record more than once.

HELP
 
W

Wayne Morgan

Execute the following append query in code. It will limit the addition of
records to those whose primary key field aren't in the second table and
where the Yes/No field is True. This will append all fields, including the
Yes/No field. If you don't want to, you would need to specify which fields
you want inserted.

INSERT INTO Table2
SELECT Table1.*
FROM Table1 LEFT JOIN Table2 ON Table1.Key = Table2.Key
WHERE (((Table1.YesNoField)=True) AND ((Table2.Key) Is Null));

Example:
Dim strSQL As String
strSQL = "INSERT INTO Table2 SELECT Table1.* FROM Table1 LEFT JOIN Table2 ON
Table1.Key = Table2.Key WHERE (((Table1.YesNoField)=True) AND ((Table2.Key)
Is Null));"
CurrentDb.Execute strSQL, dbFailOnError
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top