Update from VB

S

Stewart

I want to update the values (Budget) in a table (Budget 01) based on the
input of an input box multiplied by a percentage stored in the table
(Percentage). This is initiated when the user clicks a button from a form.

The input box pops up, but after I enter the amount (30000), I get an error:
"Microsoft Office Access can't find the field "|" referred to in your
expression"

How do I correct this?

Below is my code:

Dim strSql As String
Dim Message, Title, MyValue

Message = "What is your total budget?"
Title = "Budget" ' Set title.
' Display message, title, and default value.
MyValue = InputBox(Message, Title)

strSql = "UPDATE [Budget 01] " & _
"SET [Budget 01].Budget = " & [Budget 01]![Percentage] &
MyValue
CurrentDb.Execute strSql
 
D

Dirk Goldgar

In
Stewart said:
I want to update the values (Budget) in a table (Budget 01) based on
the input of an input box multiplied by a percentage stored in the
table (Percentage). This is initiated when the user clicks a button
from a form.

The input box pops up, but after I enter the amount (30000), I get an
error: "Microsoft Office Access can't find the field "|" referred to
in your expression"

How do I correct this?

Below is my code:

Dim strSql As String
Dim Message, Title, MyValue

Message = "What is your total budget?"
Title = "Budget" ' Set title.
' Display message, title, and default value.
MyValue = InputBox(Message, Title)

strSql = "UPDATE [Budget 01] " & _
"SET [Budget 01].Budget = " & [Budget 01]![Percentage]
& MyValue
CurrentDb.Execute strSql

Shouldn't that SQL statement be:

strSql = _
"UPDATE [Budget 01] " & _
"SET [Budget 01].Budget = " & _
"[Budget 01]![Percentage] * " & MyValue

?

I'd definitely recommend validating the value you get from the InputBox
before running this, though. Make sure it's numeric, that it's in a
plausible range, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top