Avatar of Fordraiders
Fordraiders
Flag for United States of America asked on

Update a field based on supplied variable

I have a table called:
Rebate_Qualifier
3 fields:
Rebate_ID      Entity_Value      Qualifier_ID

"Entity_Value" will always have a value in the field.

I have 2 variables    rb   and   ent

rb = SLS-000118-MAIN-A1-5-R1
ent = 5

The Rebate_Id is null
Qualifier_ID is null

Table example below:
Rebate_ID	Entity_Value	Qualifier_ID
	                AABAA	
	                AABAA	
	                AABAA	
	                AABAA	

Open in new window


What I need:
I need to update the Rebate_Id field with  variable  rb
I need to update the Qualifier_ID field with  variable  ent


Thanks
fordraiders
Microsoft AccessVBA

Avatar of undefined
Last Comment
Fordraiders

8/22/2022 - Mon
John Tsioumpris

UPDATE Rebate_Qualifier SET Rebate_Id = rb, Qualifier_ID =ent WHERE SomeCriteria

ASKER CERTIFIED SOLUTION
Gustav Brock

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
therealmongoose

dim dbs as database
dim rst as recordset
dim strsql as string

dim strPKValue as string

strPKValue = "AABAA" '<- the entity value you for the record you want updating

'This assumes entity value is unique in the table..

strsql = "Select * from Rebate_Qualifier where Entity_Value      = '" & strPKvalue & "';"

set dbs = currentdb
set rst = dbs.openrecordset(strsql)

rst.movefirst

rst.edit
rst!Rebate_ID      = RD
rst!Qualifier_ID = ent
rst.update
rst.close
set rst = nothing
dbs.close
set dbs = nothing

or you could code an update query with variables / functions and call that....
Fordraiders

ASKER
All good examples and thank you very much !!
Your help has saved me hundreds of hours of internet surfing.
fblack61