Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access table data not in consecutive rows 2

Status
Not open for further replies.

Mezzzo

Technical User
Joined
May 30, 2003
Messages
56
Location
US
Hi Group

I have the code below working thanks to one of the forum experts. I`ve run into
a strange problem. When I open the access table to view the data. I see the
first row is blank. My data is placed in the second row. It seems the data is
not being placed in consecutive rows. I wondering what I screwed up to cause
this condition. Example 1st row black, second row data, third row blank, then data again


Thanks as always.


procedure TfrmDrw.suiButton2Click(Sender: TObject);
begin
if not (MaterialTable.State in [dsInsert]) then
MaterialTable.Insert;
with MaterialTable do
begin
FieldByName('MatJoint').Value := dbcboJointTypeSelect.Text;
FieldByName('MatStockType').Value := cboMatType.Text;
FieldByName('MatPartName').Value := dbcboPartName.Text;
FieldByName('MatSpecies').Value := dbcboSpecSolid.Text;
FieldByName('MatRoughThkSolid').Value := dbedtRghThkSolid.Text;
FieldByName('MatFinishThkSolid').Value := dbedtFinThickSolid.Text;
FieldByName('MatBdftCostSolid').Value := dbedtCostBdftSolid.Text;
FieldByName('MatWasteSolid').Value := dbedtPriceSqftSheet.Text;
Post;
end;
end;

end.
 
Can't really tell what you are trying to do. But if your fields are TDBEdit then you don't need any code at all. Just delete the button and use a DBNavigator control. Then everything is taken care of for you.
 
You are right Zathras, the DBNavigator, takes care of everything, and the buttons you do not need can be made invisible.
You can remove the insert or delete buttons to suite your needs, with out coding.

Mezzzo, connect the dbNavigator to the datasource, just like all your other visual data components. There is no need to do any special coding, accept if you need to put in some pre-defined data.

If you press the insert button on the DBNavigator, a blank row will appear and the cursor will go to the first data aware control, to allow you to edit it. The modifications made in the db-aware components, will enter directly into the database, that is the reason of the strange behaviour of your table.
When you use
FieldByName('MatJoint').Value := dbcboJointTypeSelect.Text;

The combobox of the current record set is still empty, that is why you get a blank row.

If you need to do some special coding like filling in default data, use the BeforeInsert method of the table and type in:
FieldByName('MatJoint').Value := 'My Default Value';


Check out How to use Look Up fields with Tables /Queries faq102-1212 , The first part explains the database hierarchy.




Steven van Els
SAvanEls@cq-link.sr
 
Hi

Thanks for the additional information on the navigator, very helpful. What
I`m trying to do is add specific form data to the database. I have a few
edit and comboboxes that the user fills in. Hopefully each time the data
is filled in it will be added to the database. Could someone please show
me the syntax to use the BeforeInset. I hacked around but receive a error
message not enough actual parameters.

Thank You!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
It's probably easiest to use the FieldValues property of the query (dataset):
Code:
  MyQuery.FieldValues['MatJoint'] := 'MySpecialValue';


 
Put a table or query, put a datasource, a dbnavigator and your dbeditboxes, comboboxes etc. Right click your table and use the field editor and add the fields needed.

They will appear on your form like: table1Capital

Tie your db-aware controls to the datasource. In the case of an editbox you tie the property DataField to Capital.

Now all the modifications made to the DBEdit will be written directly to the Table, in the field capital.

The BeforeInsert method could be:

Table1Capital.Value = 'Buenos aires';

(assuming that "Buenos Aires" would be the default value)

I have used the "Country.DB" in the BDE Demos like an example.

Regards

Steven van Els
SAvanEls@cq-link.sr
 
Some explanations, I mixed things up.

1) If you need to insert a new record with default data

Use the OnNewRecord event



Steven van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top