B
Brad
I am working on an Access 2007 application. We have a customer table which
has a relationship with our State table.
Originally, I was using a simple SQL Insert like this (stripped down for
this example)
Mysql = “Insert into TblOrders (Order_ID, Order_State) Values
(“My_Order_IDâ€, “My_Order_Stateâ€)â€
DoCmd.RunSQL mysql
This method works fine, except if I have
DoCmd.SetWarnings False
I receive no error messages.
If I have
DoCmd.SetWarnings True
then I receive a message for every insert (we will have many good inserts
and only a small number of errors, so this isn’t going to work very well).
Perhaps there is a way to only see messages if there is a problem???
Also, as I understand it, the “Insert Into†method does not support “ON
ERROR†for better error trapping.
_ _ _
I then switched horses and changed the code to use a RecordSet to add the
records.
The code looks like this…
My_Recordset.AddNew
My_Recordset.Fields(“Order_IDâ€) = My_Order_ID
My_Recordset.Fields(“Order_Stateâ€) = My_Order_State
My_Recordset.Update
I like this method better because I can do better error trapping.
HOWEVER -
I now am receiving the following error for “some†of the records that we are
trying to add.
“You cannot add or change a record because a related record is required in
table 'tblStates'.â€
We have defined a relationship between the Order table and the States table.
The catch is that this error is being generated even when we have a
corresponding record in our state table. For example order #1 has a state
code of “MN†and it is accepted. Order #2 also has a state code on “MN†and
it is being rejected.
I have double checked the data and I have done a “Compact and Repair†on the
database.
I am really puzzled.
I am relatively new to using Access. What is the best way to insert
records? It feels like the “Record Set†method is a bit unpredictable, but
perhaps I am missing something.
Thanks for your help.
Brad
has a relationship with our State table.
Originally, I was using a simple SQL Insert like this (stripped down for
this example)
Mysql = “Insert into TblOrders (Order_ID, Order_State) Values
(“My_Order_IDâ€, “My_Order_Stateâ€)â€
DoCmd.RunSQL mysql
This method works fine, except if I have
DoCmd.SetWarnings False
I receive no error messages.
If I have
DoCmd.SetWarnings True
then I receive a message for every insert (we will have many good inserts
and only a small number of errors, so this isn’t going to work very well).
Perhaps there is a way to only see messages if there is a problem???
Also, as I understand it, the “Insert Into†method does not support “ON
ERROR†for better error trapping.
_ _ _
I then switched horses and changed the code to use a RecordSet to add the
records.
The code looks like this…
My_Recordset.AddNew
My_Recordset.Fields(“Order_IDâ€) = My_Order_ID
My_Recordset.Fields(“Order_Stateâ€) = My_Order_State
My_Recordset.Update
I like this method better because I can do better error trapping.
HOWEVER -
I now am receiving the following error for “some†of the records that we are
trying to add.
“You cannot add or change a record because a related record is required in
table 'tblStates'.â€
We have defined a relationship between the Order table and the States table.
The catch is that this error is being generated even when we have a
corresponding record in our state table. For example order #1 has a state
code of “MN†and it is accepted. Order #2 also has a state code on “MN†and
it is being rejected.
I have double checked the data and I have done a “Compact and Repair†on the
database.
I am really puzzled.
I am relatively new to using Access. What is the best way to insert
records? It feels like the “Record Set†method is a bit unpredictable, but
perhaps I am missing something.
Thanks for your help.
Brad