Solved

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

Posted on 2011-03-02
8
246 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
Independent Software Vendors: 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!

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

751 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