?
Solved

VBA SQL question

Posted on 2003-03-26
4
Medium Priority
?
160 Views
Last Modified: 2010-05-01
Hi

I'm using a SQL statement to update a table called tblMembers. In this table i want to update a field called "No_of_Rentals_at_Present". The following code works perfect but instead of letting it equal to 0, i want to decrease the current calue in the field by 1. I understand i have to change from "=", but i'm unaware what i should change it to.

"strSQL3 = "UPDATE tblMembers SET No_of_Rentals_at_Present = 0 where Member_ID=" & txtVideoMember"



Any help would be grateful.

0
Comment
Question by:rebel_vb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8210350
try this:

strSQL3 = "UPDATE tblMembers SET No_of_Rentals_at_Present = iif(No_of_Rentals_at_Present > 0,No_of_Rentals_at_Present-1,0) where Member_ID=" & txtVideoMember


this will test to be sure that you are not trying to SUBTRACT 1 from the value when it is already 0, but will subtract 1 if the current value is 1 or more.

Arthur Wood
0
 
LVL 1

Expert Comment

by:DeepBlueInVB
ID: 8210578
"UPDATE tblMembers
  SET No_of_Rentals_at_Present =
(case WHEN (No_of_Rentals_at_Present > 0)
THEN No_of_Rentals_at_Present -1
ELSE 0 END)
where Member_ID= '" & txtVideoMember & "'"
0
 

Accepted Solution

by:
PeterNolan earned 75 total points
ID: 8211899
Hi,

Instead of hard coding the value why not introduce another variable.

For instance

Dim intValue as integer

intValue = 1

strSQL3 = "UPDATE tblMembers SET No_of_Rentals_at_Present = " & intValue & " where Member_ID=" & txtVideoMember"

This way you can continually change the value you are looking for.

Peter
0
 

Expert Comment

by:CleanupPing
ID: 8531574
Hi rebel_vb,
This old question (QID 20563711) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question