Decrement Number in table

I

iwasinnihon

I want to be able to decrement a number in a field on a table when I
click a button on a form. I tried the following code

sql = "UPDATE Software SET TotalLicensesCount = TotalLicensesCount - 1
WHERE SoftwareID = '" & Me!Software.Column(0) & "';"
CurrentDb.Execute sql, dbFailOnError

I get the following error.

Data type mismatch in criteria expression.

What am I doing wrong.
 
J

Jeff L

I would assume that SoftwareID is a number and not a text value. In
your Where Clause you are using a text value because of the single
quote marks in the statement. Remove the single quotes and try again.

Hope that helps!
 
F

fredg

I want to be able to decrement a number in a field on a table when I
click a button on a form. I tried the following code

sql = "UPDATE Software SET TotalLicensesCount = TotalLicensesCount - 1
WHERE SoftwareID = '" & Me!Software.Column(0) & "';"
CurrentDb.Execute sql, dbFailOnError

I get the following error.

Data type mismatch in criteria expression.

What am I doing wrong.

Let's see. You have a table named "Software" and you have a combo box
named "Software". How confusing it must be to Access.

For starters, I would suggest, at the very least, that you change the
name of the combo box. Perhaps cboSoftware. (I would also change the
table neme to tblSoftgware, but that is your call.)

Next, is the cboSoftware.Column(0) the bound column of the combo box?
What is the datatype of the [SoftwareID] field? I would suspect it is
Number datatype, not text.
So, assuming Number datatype, and that the (0) column is the bound
column, then:

sql = "UPDATE Software SET Software.TotalLicensesCount =
TotalLicensesCount - 1 WHERE Software.SoftwareID = " & Me!cboSoftware

should work.
 

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