Solved

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

Posted on 2011-03-02
8
227 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
ID: 35020189
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
ID: 35020221
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
ID: 35020274
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 74

Expert Comment

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

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35020748
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
ID: 35021015
The filter is another form with a query on the table.

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35021355
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
ID: 35024609
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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