Update ID to another table

G

Grizz

In my partial code below I am updateting two tables at the same time, What is
the code to pass the new Autonumber from the one table rec2 to the other
table rec? This is how my relationship is setup

Also notice the Truck ID in rec statement, This is from a combobox, How can
I get just the ID sent not the actual number? I have tried
Me!CmbTruckNumber.ID or TruckID as the field is called, I have a code in
place for the combobox to update new Truck number if not listed.



Set rec = dbLocal.OpenRecordset("LoadInfoTbl", dbOpenDynaset)
Set rec2 = dbLocal.OpenRecordset("EquationTbl", dbOpenDynaset)

With rec2
.AddNew
!Exspense = Me!TxtExspense
!PlantDiscount = Me!TxtPlantDiscount
!PurchasePrice = Me!TxtBoughtPrice
!HotPrice = Me!TxtHotPrice
!HaulCost = Me!TxtHaulCost
!Yield = Me!TxtYield
.Update

End With
With rec
.AddNew
!BuyDate = Me!TxtDate
!Weight = Me!TxtWeight
!Mileage = Me!TxtMileage
!Rate = Me!TxtRate
!BuyPrice = Me!TxtBuyPrice
!TruckID = Me!CmbTruckNumber
.Update
End With

Thank You
 
M

Mike Painter

I'm not sure when teh autonumber is assigned. It may be available as soon as
you add the first field info.
In that case
rec.othernumber = rec2.autonumberfield.
If that fails you will have to use a soevents and get it from teh last
record.
Simply binding your tables to the form would do the same thing by using a
subform that only showed a single record.
Your combobox would notmally return the ID of the record as opposed to some
other value but I'm not sure I know exactly what you are asking.
 

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