Solved

Adding or Subtracting a % from a list of values in a continous form in Access

Posted on 2011-03-02
8
208 Views
Last Modified: 2012-05-11
I have a continuous form with 2 fields:
[Last_Quarter_Forecast] and [Last_Quarter_Actual]

I would like to add the following 2 buttons on in the header of the form:
[-5%] and [+5%]
The 2 button should increase (or decrease) all the values displayed in [Last_Quarter_Actual] by 5% on every click

What the VBA code of the buttons should be?

Thank you as always for your support
0
Comment
Question by:fitaliano
  • 5
  • 2
8 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Code to Add 5% to [Last_Quarter_Forecast].

I am sure you can figure out the rest on your own...

;-)

JeffCoachman

Private Sub cmdAdd5_Click()
    CurrentDb.Execute "UPDATE Orders SET [Last_Quarter_Forecast] = ([Last_Quarter_Forecast]*0.05)+[Last_Quarter_Forecast];"
    Me.Requery
End Sub
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Or a little safer:

Private Sub cmdAdd5_Click()
    CurrentDb.Execute "UPDATE YourTable SET [Last_Quarter_Forecast] = ([Last_Quarter_Forecast]*0.05)+[Last_Quarter_Forecast];",dbfailonerror
    Me.Requery
End Sub

0
 

Author Comment

by:fitaliano
Comment Utility
Thank you boag2000 but I actually don't want to update the entire table but only the records displayed by the form.  Sorry for not specifying this in my initial quetion.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Then will youi be telling me what the filter is?
;-)

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Actually you might do better with this for my first solution...:
Private Sub cmdAdd5_Click()
    CurrentDb.Execute "UPDATE YourTable SET [Last_Quarter_Forecast] = [Last_Quarter_Forecast]+([Last_Quarter_Forecast]*0.05);",dbfailonerror
    Me.Requery
End Sub
0
 

Author Comment

by:fitaliano
Comment Utility
The filter is another form with a query on the table.

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Until you tell me what the filter is and how, exactly, it is being applied we are at an impasse here...

How about you post a sample DB:
Sample database notes:
1. Back up your database(s).
2. Combine the front and back ends into one database file.
3. Remove any startup options, unless they are relevant to the issue.
4. Delete any objects that do not relate directly to the issue.
5. Remove any references to any "linked" files (files outside of the database, Images, OLE Files, ...etc)
6. Remove any references to any third party Active-x Controls (unless they are relevant to the issue)
7. Remove, obfuscate, encrypt, or otherwise disguise, any sensitive data.
8. Compile the code. (From the database window, click: Debug-->Compile)
9. Run the compact/Repair utility.
10. Remove any Passwords and/or security.
11. Post explicit steps to replicate the issue.
12. Test the database before posting.

In other words, ...post a database that we can easily open and immediately see the issue.

JeffCoachman
0
 
LVL 3

Accepted Solution

by:
DockieBoy earned 500 total points
Comment Utility
Maybe you could loop through the record source for your form and make the changes, then requery your form?

Private Sub MyButton_Click()
 Dim db as DAO.Database
 Dim rs as DAO.Recordset
 Dim ssl as string
  Set db = CurrentDb
  ssl = "select * from MyRecordSource where UseFileterHere;"
  Set rs = db.OpenrecordSource(ssl)
 If rs.RecordCount = 0 then
  Set db = Nothing
  Set rs = Nothing
  Exit Sub
 Else
  With rs
   .MoveFirst
   Do While Not .EOF
   'Make your changes here'
   .Update
   .MoveNext
  Loop
 .Close
 End With
 End If
  Set db = Nothing
  Set rs = Nothing
 Me.Requery
End Sub
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now