Update Field in Table

charlee63

Board Regular
Joined
Jan 7, 2010
Messages
146
This is my first time doing this function. Can someone tell me what I'm doing wrong?
1690304235486.png

Sub getretails()
Dim o As DAO.Recordset
Dim bot As Variant
Dim top As Variant

Set o = CurrentDb.OpenRecordset("TblRetail")

While Not o.EOF

bot = Round(o![GM%].Value, 2)
top = o![GM%].Value + 0.05

Dim cost As Variant
cost = 0

Dim x As Integer
x = 3

Dim ret As Variant
ret = 0

cost = o![Unit Net].Value
ret = cost / (1 - bot)
tempInt = ret
If (tempInt = theValue) Then 'check if original value was already whole
'do nothing
Else
tempInt = tempInt + 1 'value was not whole integer, add one to round up
End If
roundUp = tempInt 'return rounded value
ret = roundUp - 0.01

gp = (ret - cost) / ret
Do While gp > top
ret = ret - 0.1
gp = (ret - cost) / ret
Loop
CurrentDb.Execute "Update tblRetail set Retail = Round(ret, 2)"

o.MoveNext
Wend

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Walk through your code. :(
What is tempint, thevalue, gp?

Put in some debug.print statements if you do not want to walk that code.
 
Upvote 0
Probably want to include some criteria in your Update statement as well.
 
Upvote 0

Forum statistics

Threads
1,224,885
Messages
6,181,576
Members
453,055
Latest member
cope7895

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top