Am I missing something? For some reason I have a dao recordset that sets my autonumber field to zero (0). At first I thought that it wasn't returning the new autonumber id but when I opened the table there was the record but the autonumber field was 0. I have tried numerous ways to get it to work. What is going on?
I tried setting the db connection using Set db = CurrentDb instead of Set rs = CurrentDb.OpenRecordset("tblEstimate"). I've compressed database, I compiled database/I created a new table from scratch and even renamed it from tblEstimating to tblEstimate. I also tested another procedure that is the same but to a different table and it works.
I tried setting the db connection using Set db = CurrentDb instead of Set rs = CurrentDb.OpenRecordset("tblEstimate"). I've compressed database, I compiled database/I created a new table from scratch and even renamed it from tblEstimating to tblEstimate. I also tested another procedure that is the same but to a different table and it works.
Code:
Set db = CurrentDb
Set rs = db.OpenRecordset("tblEstimate")
With rs
.AddNew
!CustomerID = LCustID
!EstID = LEstID
!Empid = LAddEdit
!SalesRepID = LSales
!EstStatusID = LStatus
!estcode = sEstCode
!DateCreated = dDate
!DueDate = dDue
!CompletedOn = dComp
!dateaccepted = dAccept
!TotalEstimate = cTotalEst
!SubTotal = cSubTotal
!DiscountPercent = sngDiscPercent
!DiscountAmt = cDiscAmt
!TaxAmt = cTaxAmt
!TaxTypeID = LTaxType
!Qty = sngQty
!jobdescription = sJobDesc
!OtherCost = 0
!ShipCost = cShip
!empcost = cEmpCost
!deposit = cDeposit
!BillAdd1 = sBAdd1
!BillAdd2 = sBAdd2
!BillCityName = sBCity
!BillStateID = LBState
!BillPostal = sBZip
!ShipAdd1 = sSAdd1
!ShipAdd2 = sSAdd2
!ShipStateID = LSState
!ShipCityName = sSCity
!ShipPostal = sSZip
!AddedOn = dAddEditOn
!AddedBy = LAddEdit
!ShipTo = sSTo
!BillTo = sBTo
.Update
.Bookmark = .LastModified
LEstID = !EstID
Debug.Print !EstID
SaveEstimate = LEstID
rs.Close
End With
Procedure that works
Set rs = CurrentDb.OpenRecordset("tblMediaSizes")
With rs
.AddNew
!depthMeasurementID = iDepthMea
!HeightMeasurementID = iHeightMea
!WidthMeasurementID = iWidthMea
!MediaTypeID = LMediaTypeID
!SizeName = sSize
!LengthMeasurementID = iLengthMea
!Width = sngWidth
!Length = sngLength
!Depth = sngDepth
!Height = sngHeight
!AvgCost = cCost
!CostPerInch = cInch
!CostPerFoot = cFoot
!Qty = 1
!RequiredMediaID = LRequiredMediaID
!TotalInchesInRoll = sngTotalInchesInRoll
.Update
.Bookmark = .LastModified
LMediaSizeID = rs!MediaSizeID
.Close
MsgBoxRecordSaved
bDirty = False
End With