Need some help with Delphi and MS Access
Posted on 2004-09-30
I am developing an Asset tracking system in Delphi 6, with an Access DB as a backend.
Basically I have two tables, one called ASSETS, one called COMPONENTS. Basically an Asset can have many Components, therefore ASSETS is the Master, COMPONENTS is the child.
The following Table structures Apply
................ other fields not needed
...................... other fields not needed
What I want to do is, be able to Insert a Record in the ASSET table, GET the AssetID Number, and then use this to Insert multiple records in the COMPONENTS Table. I have thought about using a query to Get the MAXIMUM value, the problem with this is, because the Application will be accessed by Multiple users, Many staff could be adding records at the same time, so how do I get the Current AssetID No for the Current User.
I am using the following code to Insert Records in the ASSET Table at the moment
if rbComp.Checked then sType:='COMPUTER';
if rbNoteBk.Checked then sType:='NOTEBOOK';
if rbPrinter.Checked then sType:='PRINTER';
'INSERT INTO detsAssets ( AssetNo, AssetType)'+#13+
'VALUES ("'+sAsset+'", "'+sType+'"')';
Therefore, when I do an INSERT, I want to get the Appropriate AssetID. I have thought about using the MAX and the AssetNo, BUT the AssetNo Field could contain BLANK values.
Any ideas would be greatly appreciated