Solved adding numbers in code

murray83

Games Collector
Local time
Today, 21:33
Joined
Mar 31, 2017
Messages
845
have this code at moment

CurrentDb.Execute "Update tbl_GoodGuy set [YourHealth] = " & Me.Text133 & " WHERE [GoodGuy] = 'Player'"

but i want to flip it so when user presses command it takes the health count and adds an arbitrary number of my choosing to it ( the number will be the same each time

but when i try and put a + it dont like it, what should i be doing
 
starts saying in the code

Execute Query as string

dont get as far as trying to run as not sure doing it right
 
starts saying in the code

Execute Query as string

dont get as far as trying to run as not sure doing it right
Okay, you did say the code you posted was working, right? What is in Text133 when you run that code? What does it look like when you changed it that Access didn't like?
 
CurrentDb.Execute "Update tbl_GoodGuy set [YourHealth] = " & Me.Text133 & " WHERE [GoodGuy] = 'Player'"

To flip it to add some predefined number to the existing health count (rather than adding it to the text box contents), that would be

Code:
CurrentDb.Execute "Update tbl_GoodGuy set [YourHealth] = [YourHealth] + " & CStr(Some-arbitrarily-defined-number  ) & " WHERE [GoodGuy] = 'Player'"
 
you may also try:

CurrentDb.Execute "Update tbl_GoodGuy set [YourHealth] = [YourHealth] + " & Val(Me.Text133 & "") & " WHERE [GoodGuy] = 'Player'"
 
To flip it to add some predefined number to the existing health count (rather than adding it to the text box contents), that would be

Code:
CurrentDb.Execute "Update tbl_GoodGuy set [YourHealth] = [YourHealth] + " & CStr(Some-arbitrarily-defined-number  ) & " WHERE [GoodGuy] = 'Player'"

Bloody Awesome, works a charm, now just got to fix it so cant keep spamming it cheers @The_Doc_Man
 
attached is the WIP with the now working potion button ( well it works as in it gives health back but need to just fix the time you can use ) thanks all
 

Attachments

CurrentDb.Execute "Update tbl_GoodGuy set [YourHealth] = [YourHealth] + " & CStr(Some-arbitrarily-defined-number ) & " WHERE [GoodGuy] = 'Player'"
This is working because the whole expression is a string. Normally, you wouldn't get away with adding a string to a number.
 

Users who are viewing this thread

Back
Top Bottom