DBarker said:
I tried this code, I have multiple fields to change names
on and this code did not work. Do I have to do a separate
one for each?
-----------------------------------------------------------
Function ChangeFieldValue(FieldName As String, Value As
String)
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("STi", dbOpenDynaset)
With rst
.Edit
.Fields(SWDATECREATED) = EntryDate
.Update
.Edit
.Fields(SUCODE) = Region
.Update
.Edit
.Fields(SUDEALERCODE) = Dealer
.Update
.Edit
.Fields(SWNAME) = DealerName
.Update
.Edit
.Fields(SWADDRESS1) = Address1
.Update
.Edit
.Fields(SWADDRESS2) = Address2
.Update
.Edit
.Fields(SWCITY) = City
.Update
.Edit
.Fields(SWSTATE) = State
.Update
.Edit
.Fields(SWZIP) = ZipCode
.Update
.Edit
.Fields(SWASSETTAG) = VINPrefix
.Update
.Edit
.Fields(SWSERIALNUMBER) = VIN(Last8)
.Update
.Edit
.Fields(SUMILEAGE) = Mileage
.Update
.Edit
.Fields(SUPRODDATE) = ProdDate
.Update
.Edit
.Fields(SUFAILURECODE) = FailCode
.Update
.Edit
.Fields(Expr1001) = Condition
.Update
.Edit
.Fields(Expr1002) = Journals
.Update
.Edit
.Fields(SWCREATEDBY) = UserID
.Update
.Edit
.Fields(SUENGINECYLINDERDESC) = EngineSize
.Update
.Edit
.Fields(SUENGINENBR) = EngineNum
.Update
.Edit
.Fields(SUTRANSMISSION) = TransNum
.Update
.Edit
.Fields(SWCASEID) = CaseNum
.Update
.Edit
.Fields(SUSECTION) = Section
.Update
.Edit
.Fields(SUSUBSECTION) = SubSection
.Update
.Edit
.Fields(SWKEYWORDS) = Keywords
.Update
.Edit
.Fields(SULASTMODIFYDATE) = LastModified
.Update
End With
The original code was intended to update a field whose name is passed as
a string argument. In your case, you are hard-coding the names of the
fields. Try it like this:
With rst
.Edit
.Fields("SWDATECREATED") = EntryDate
.Fields("SUCODE") = Region
.Fields("SUDEALERCODE") = Dealer
.Fields("SWNAME") = DealerName
.Fields("SWADDRESS1") = Address1
.Fields("SWADDRESS2") = Address2
.Fields("SWCITY") = City
.Fields("SWSTATE") = State
.Fields("SWZIP") = ZipCode
.Fields("SWASSETTAG") = VINPrefix
.Fields("SWSERIALNUMBER") = VIN("Last8")
.Fields("SUMILEAGE") = Mileage
.Fields("SUPRODDATE") = ProdDate
.Fields("SUFAILURECODE") = FailCode
.Fields("Expr1001") = Condition
.Fields("Expr1002") = Journals
.Fields("SWCREATEDBY") = UserID
.Fields("SUENGINECYLINDERDESC") = EngineSize
.Fields("SUENGINENBR") = EngineNum
.Fields("SUTRANSMISSION") = TransNum
.Fields("SWCASEID") = CaseNum
.Fields("SUSECTION") = Section
.Fields("SUSUBSECTION") = SubSection
.Fields("SWKEYWORDS") = Keywords
.Fields("SULASTMODIFYDATE") = LastModified
.Update
End With
You only need one .Edit and one .Update to edit all the fields in the
current record of the recordset and then save it. Do you really have
fields in your table named Expr1001 and Expr1002?