P
Peter Hibbs
Access 2003 SP3
I have a table (tblProducts) which has about 50 fields, the main field
is named ItemCode (Text) which defines the product code. The field is
Unique and Indexed (No Duplicates).
The users often have to add a new product to the table which is
sometimes almost identical to an existing product in the table, i.e.
Widget-Red, Widget-Green, etc. So rather then having to enter the same
data in all the fields I want to provide them with a button on the
Products Entry form which will 'clone' the existing record.
The idea is that they would find a similar product to the new one,
click the Clone button which would pop up a form into which they can
enter a new item code and when they click an OK button it will add
another record to the products table which will have the new item code
but the same data from all the other fields.
Now that is relatively easy to do using SQL BUT what I would like to
do, if possible, is to do it without referencing the field names. The
reason for that is I occasionally have to add a new field to the
products table and it is quite possible that I will forget that I also
will need to change this code each time I do that.
What I had in mind was something like :-
CurrentDb.Execute "INSERT INTO tblProducts SELECT * FROM tblProducts
WHERE ItemCode = '" & txtOldProduct & "'"
This doesn't work, of course, because the ItemCode field is Unique so
the new record does not get added to the table. I could create a new
record first with the INSERT INTO command and then use UPDATE to
update the other 50 fields from the existing record but that has to be
done by defining each field name in turn.
Is there any way to do an UPDATE without knowing the field names or
how many fields there are in the table?
Thanks.
Peter Hibbs.
I have a table (tblProducts) which has about 50 fields, the main field
is named ItemCode (Text) which defines the product code. The field is
Unique and Indexed (No Duplicates).
The users often have to add a new product to the table which is
sometimes almost identical to an existing product in the table, i.e.
Widget-Red, Widget-Green, etc. So rather then having to enter the same
data in all the fields I want to provide them with a button on the
Products Entry form which will 'clone' the existing record.
The idea is that they would find a similar product to the new one,
click the Clone button which would pop up a form into which they can
enter a new item code and when they click an OK button it will add
another record to the products table which will have the new item code
but the same data from all the other fields.
Now that is relatively easy to do using SQL BUT what I would like to
do, if possible, is to do it without referencing the field names. The
reason for that is I occasionally have to add a new field to the
products table and it is quite possible that I will forget that I also
will need to change this code each time I do that.
What I had in mind was something like :-
CurrentDb.Execute "INSERT INTO tblProducts SELECT * FROM tblProducts
WHERE ItemCode = '" & txtOldProduct & "'"
This doesn't work, of course, because the ItemCode field is Unique so
the new record does not get added to the table. I could create a new
record first with the INSERT INTO command and then use UPDATE to
update the other 50 fields from the existing record but that has to be
done by defining each field name in turn.
Is there any way to do an UPDATE without knowing the field names or
how many fields there are in the table?
Thanks.
Peter Hibbs.