Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-02
8
Medium Priority
?
255 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
[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
  • 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

688 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