Modules & VBA :: Subtracting Value On Current Record From The Value Of Previous Records?

Jun 5, 2013

I want subtrack a value on the current record from the previous record and display the result in text box in subform datasheet. This is done during data entry. The calculation works most of the time and randomly it returns the wrong value. I have the code in an after update event after I enter a number. Here is what my code looks like:

sysHopSpacing = Abs([sysHop1] - DLookup("[sysHop1]", "tblSystemConfiguration", "[sysBaseNumber]=Forms![frmTempestCoordination]![frmSubSystem]![sysBaseNumber] - 1 "))

This is how I generate the sysBaseNumber

sysBaseNumber = Nz(DMax("sysBaseNumber", "tblSystemConfiguration", "sysAccountID=" & Forms!frmTempestCoordination!accAccountID), 0) + 1

I am using DMax so I can keep the subform records with the parent form record.

My results are inconsistant:

This is what I want the subform to do when subtracking from the previous record

syshop1 sysHopSpacing
5
20 15
30 10

Instead I get a result that does not make sense like this:

sysHop1 sysHopSpacing
5
20 15
30 4

I cant trace it down.

View Replies


ADVERTISEMENT

Dynamically Update Field Of A Current Record Based On Previous Record

Apr 30, 2007

I need a way to dynamically store a particular value in "field_2" of the CURRENT record depending on whether or not the value of "field_1" of the CURRENT record is identical to the value of "field_1" of the PREVIOUS record within the same table. The table is sorted on "field_1".

So, if the value of "field_1" in the CURRENT record is "ABC" and the value of "field_1" in the PREVIOUS record is also "ABC", then store a value of "PPP" in "field_2" of the current record. IF on the other hand, the value of "field_1" in the CURRENT record is "ABC" and the value of "field_1" in the PREVIOUS record is "XYZ", then store a value of "WWW" in "field_2" of the current record.

I have a report that will use these results to count only the number of records that have a "WWW" in "field_2".

Is this doable, maybe in a query somehow?

I should add that whatever the solution, it needs to be compatible with Access 2000.

View 1 Replies View Related

Queries :: Evaluating Current Record To Previous Record To Get Counts

Aug 8, 2014

I'm struggling with a query to evaluate current and prior record data. I have a query producing 5000 records. I need to group records by Case ID and compare current date record to previous date record to determine if a team and worker name has changed during the year. I need to count how many times a cases is transferred to and out of a particular team from the beggining of the year. i.e., On 1/1/2014-Team1 has an inventory of 500 cases.

During the month 25 cases are transferred into Team1 and 15 cases are transferred out of Team1. So on 2/1/2014 Team1 begins with an inventory of 510 cases. Throughout the year cases come and go from and to Team1 each month so need to figure out how to create a query to count each change. See attachment displaying how the data is listed and how I invision it to work with the In/out column counts.

Specifically, at the begginig of the year (1/1/14) for case ID 1003 you can see it belongs to Mary in Team1 for January and February. Then in March the case is transferred out and went to Joe in Team 3. So for Mary a "-1" is recorded as a negative count for that Case ID. If later in the year the case is transferred back to Mary a "+1" would be recorded. Respectively evaluated for each of the 5000 records to get a total count for each of the teams by Case ID throughout the year.

I've started with DLookup, tried comparing current month to previous month using DMax. It works as long as I only select one case ID used in a separate query but if I use the whole subset (5000 records) it fails. I can't figure out how to group each set of case IDs and then apply the query.

My attempted query: DLookUp("[Team]","[Team_qry]","[Team_qry]![Date]=#" & CStr(DMax("[Date]","[Team_qry]","[Team_qry]![Date] <#" & CStr([Date]) & "#")) & "#")

View 3 Replies View Related

Refer To Previous Record In Current Record Query

Sep 15, 2005

In my query, i want to automatically display the value of another field from the previous record in a field in my current record. i.e.

Name Value Previous
Record 1 1
Record 2 2 1
Record 3 7 2
Record 4 1 7

Is it possible to create some kind of simple expression to refer to data in another record?

Cheers,
Ben

View 6 Replies View Related

Compare Current To Previous Record In Query

Aug 14, 2007

I have a table of customers who report trouble on their equipment. I would like to compare the date in the current record to the previous record to see if it occurred within 30 days. Can I do this with an SQL query or expression?

View 2 Replies View Related

Queries :: Datediff From Previous To Current Record

Oct 10, 2013

I want to get the datediff of the last returned date from vacation and the current vacation start date. But how to get difference from the previous record's date to this current record's date. I want to show date difference in an unbound textbox. I have a contiuous form which shows all vacation list of employees. It shows how many times he went vacations and when he went and when he returned.

View 14 Replies View Related

Conditional Format Based On Previous And Current Record

Feb 4, 2005

I'm having trouble with a tricky conditional format in a continuous subform.

The criteria is based on field [GroupNo] when it changes (increases) which are always listed in numerical order.

Basically all I want to is for the text box colour to alterante (eg blue & yellow)when GroupNo changes value

So it would look something like this....

Group NoID (highlight colour)

1 (yellow)
1 (yellow)
1 (yellow)
2 (blue)
2 (blue)
2 (blue)
3 (yellow)
3 (yellow)
etc etc

btw, although values will always be in order they may not all be output, so it's not just case of odd, even, odd, even (that would be too easy!)

I can retrieve the Previous Record's GroupNo value (via a function) in another text box and compare current GroupNoID with this in the Format Expressions and manage to change the colour, but it won't sustain this new colour for the subsequent same GroupNos, obviously as the values have changed.

So how can I....

Change the colour when the value changes.
Keep this new colour until it the value changes (increases) again.

Many Thanks

View 14 Replies View Related

Forms :: Return To Previous Current Record After Requery

Jul 30, 2013

I have a Main form that has button that loads a new Pop Up form for entering new data that will display in the Main form. When all the data is entered I click on a button that Saves the data and exits the form and then runs Re-query on the main form returning to the record that was current before the requery.

I have the following code:

Private Sub cmdSaveTradeAndExit_Click()
DoCmd.RunCommand acCmdSaveRecord 'Save the current record
DoCmd.Close 'Close the current form
Dim CrId As Integer
CrId = Forms!frmTransactionMainActivePopUp.CurrentRecord
Forms!frmTransactionMainActivePopUp.Requery
DoCmd.GoToRecord , Forms!frmTransactionMainActivePopUp, acGoTo, CrId
End Sub

But I am getting the following error:

Run-time error '2498':

An expression you entered is the wrong data type for one of the arguments

And the following is in yellow in the debug:

Code:
DoCmd.GoToRecord , Forms!frmTransactionMainActivePopUp, acGoTo, CrId

View 4 Replies View Related

Problem With Harvesting Records By Date Spaning The Previous And Current Years

Mar 3, 2005

Im working on a make-table query that harvest records for calculation that span a "rolling" 13 week history... my problem is that the query will work if it doesn't have to retrieve work weeks that are prior to the new year. For example, right now is the tenth week of this year so i need to grab the previous 9 weeks of history plus 4 weeks of the prior year. then next week when the query is ran we will be in the 11th work week of the year therefor i will need to harvest the past 10 week plus 3 week of the preivious year. the query works if you don't have to span accross calendar years. here is the SQL of the query below the problem area is in underlined in bold type:
SELECT PORVPHIS.VENDOR_ID, PORVPHIS.VEND_NAME, [Expr2] AS [Fiscal Year], DatePart("yyyy",[DATE_RECV]) AS Expr2, DatePart("ww",[DATE_RECV]) AS Expr1, PORVPHIS.QTY_RECVD, PORVPHIS.PO_UNT_PRC, [PO_UNT_PRC]*[qty_recvd] AS [Total Price], [Expr1] AS [Fiscal Week], IIf([fiscal week]=[LowWeek] And [Expr3]<>0,[total price],0) AS 1, IIf([fiscal Week]=[LowWeek]+1 And [Expr3]<>0,[total price],0) AS 2, IIf([fiscal Week]=[LowWeek]+2 And [Expr3]<>0,[total price],0) AS 3, IIf([fiscal Week]=[LowWeek]+3 And [Expr3]<>0,[total price],0) AS 4, IIf([fiscal Week]=[LowWeek]+4 And [Expr3]<>0,[total price],0) AS 5, IIf([fiscal Week]=[LowWeek]+5 And [Expr3]<>0,[total price],0) AS 6, IIf([fiscal Week]=[LowWeek]+6 And [Expr3]<>0,[total price],0) AS 7, IIf([fiscal Week]=[LowWeek]+7 And [Expr3]<>0,[total price],0) AS 8, IIf([fiscal Week]=[LowWeek]+8 And [Expr3]<>0,[total price],0) AS 9, IIf([fiscal Week]=[LowWeek]+9 And [Expr3]<>0,[total price],0) AS 10, IIf([fiscal Week]=[LowWeek]+10 And [Expr3]<>0,[total price],0) AS 11, IIf([fiscal Week]=[LowWeek]+11 And [Expr3]<>0,[total price],0) AS 12, IIf([fiscal Week]=[LowWeek]+12 And [Expr3]<>0,[total price],0) AS 13, DatePart("ww",Now())-13 AS LowWeek, IIf([fiscal Week]>=[LowWeek] And [fiscal year]<>DatePart("yyyy",Now()),0,[LowWeek]) AS Expr3, [LowWeek] AS week1, [LowWeek]+1 AS week2, [LowWeek]+2 AS week3, [LowWeek]+3 AS week4, [LowWeek]+4 AS week5, [LowWeek]+5 AS week6, [LowWeek]+6 AS week7, [LowWeek]+7 AS week8, [LowWeek]+8 AS week9, [LowWeek]+9 AS week10, [LowWeek]+10 AS week11, [LowWeek]+11 AS week12, [LowWeek]+12 AS week13, PORVPHIS.DATE_RECV, IIf([Expr4]="AS8819" Or [Expr4]="CO1870" Or [Expr4]="GV2510" Or [Expr4]="MC3105",[VEND_NAME],Null) AS ID, PORVPHIS.VENDOR_ID AS Expr4 INTO Tporv

FROM PORVPHIS

WHERE (((PORVPHIS.VENDOR_ID)="AS8819" Or (PORVPHIS.VENDOR_ID)="CO1870" Or (PORVPHIS.VENDOR_ID)="GV2510" Or (PORVPHIS.VENDOR_ID)="MC3105" Or (PORVPHIS.VENDOR_ID)="IM2680") AND ((DatePart("yyyy",[DATE_RECV])) Between DatePart("yyyy",Now())-1 And (DatePart("yyyy",Now()))) AND ((DatePart("ww",[DATE_RECV])) Between DatePart("ww",Now())-1 And (DatePart("ww",Now()))-13));

I hope some one can help me......you can email me by markphillipsii@bellsouth.net or mphillips@dccabinetry.com

thanks Mark

View 1 Replies View Related

Reports :: Subtracting From Previous Line In Report To Make Running Total

Jun 16, 2014

I have a database and one of the functions is to track the purchase of fuel. Part of purchasing fuel is registering what the current odometer reads. My query gets the Vehicle ID, Date of Transaction and Odometer reading. I want to show a report that shows how many miles the vehicle is has traveled for a certain amount of time. If it's for 2013 then I'll put the criteria for 2014 in the date. This will give me a list of all vehicles and their odometer readings. I then sort the date by ascending.

In the report I group on vehicle ID and then I want to show all their transactions and add up how many miles were driven.

Vehicle 1

1/2/201
1/5/2013
1/15/2013
ETC...
Total Miles Driven in 2014: XXXXXX

View 1 Replies View Related

Adding And Subtracting Dates From Current Date

May 7, 2013

My first question is how to set a column to be the current date read by the computer.

Example: It will automatically say 5/8/2013 tomorrow without needing updating.

Question 2: How to add a number of days to the current date.

Example:

Add 7 days to the current date.

on 5/8/2013 it will read 5/15/2013, then automatically update to 5/16/2013 on 5/9.

View 1 Replies View Related

Having A Records Calculated Field Get Info From Previous Record

Jan 20, 2007

I have a table (tblStats). The user enters his current weight in a field named Wt. There are 2 other fields in the table named WkLoss and TTDLoss. These two fields are intended to be calculated. What I am trying to do is when the user enters his current weekly weight figure into the Wt field, I want the field WkLoss to get the user's weight from the previous record and place the difference in the field WkLoss. Also I would like to keep a total to date in the TTDLoss field.

So far this has been my attempt.
Code:Public Sub setWeight()Dim rs As DAO.RecordsetDim Startval As DoubleStartval = 190Set rs = CurrentDb.OpenRecordset("tblStats")'Select records to be updatedSet rs = CurrentDb.OpenRecordset _("SELECT * FROM tblStats ") rs.MoveFirst Do rs.Edit'field to update rs.Fields("WkLoss") = Startval rs.Update rs.MoveNext'increment step value Startval = WkLoss - Wt Loop Until rs.EOF rs.Close Set rs = Nothing End Sub
All I get is the value 190 placed in the first record and all zeros in the subsequent records. Also I don't have a clue as to how to get the Total To Date field to calculate.

Any help would be appreciated
Thanks for your time.

View 1 Replies View Related

Modules & VBA :: Using Previous Records To Find Totals

Feb 18, 2014

Basically what I have is a form where operators can input certain information about a production process, in particular the kg input which has gone into the 'basket'. However this is divided by customer order number and sometimes more than one customers order is placed into the same basket. This means that the weight of the record is not representative of the weight in the basket, and it is the weight of the basket which determines efficiency in the process.

Each basket is designated a 'Disc Number' which is put in the basket so the parts contained can be identified after the process. What I am trying to do is right a code, whether in my table or form (or somehow creating a query) which compares the disc number of the previous record (or previous 2 or 3) and if they are the same the totals are combined. Each record the user places has a hidden ID which keeps them in order, and the records with the same disc number will always be entered after one another in that sequence.

How would I be able to code something to deal with this and where would I put it?The table in question which contains the records is called Thetatbl and then form it links to is Thetafrm. The weight of each record is contained in Orderkgtxt.

View 7 Replies View Related

Modules & VBA :: Linking Tables By Auto Inserting A Record Using Current Record

Aug 19, 2013

I have two forms both with separate tables

(1) Register and
(2) Payments.

One of the common denominators between them is the URN which is auto-populated as it is an auto number field. My issue is that when I want to add a new record to the payments table using the forms (I can get to the payments form via the register form), I want to be able to identify the record that I am currently viewing within the register and auto populate the URN field with the same number. This is what I have done so far,

Option Compare Database
Option Explicit
Private Sub AttachPaymentDetails()
Call PerformInsert("tblFinancialBudget", "frmFinancialBudget")
End Sub

[code]....

View 5 Replies View Related

Modules & VBA :: Next / Previous Record In A Form But For Specific Value

Jul 16, 2015

I was wondering if there is a code for Next and Previous record in a form but for a specific value.

Example: I have a customer that has a specific ID and that customer has a list of orders that all contain that ID. When I open a form for orders I would like to be able by using Next and Previous record buttons to be able that was to move only through records of that customer not the whole list of orders for every customer.

View 1 Replies View Related

Modules & VBA :: Calculations Using Previous Record Calculation

Oct 4, 2013

I have partially done it using PrevRecVal module I found on the web.

I created what I need to do in Access in Excel first, the problem doing this in Access (for me) is I need to refer to the results in the previous record, PrevRecVal worked but I need to finish if possible.

The main report holds client policy data of which InvestAmount is used to start the calculation of the sub report, the data entered to run the calculations on the subreport would be

QtrDate
CurrentUnitPrice

The Excel spreadsheet is attached ....

View 10 Replies View Related

Modules & VBA :: Display Last Record Next To Empty Space On Current Record

May 6, 2015

I'm trying to make a form that shows what the last record was next to the empty space where you enter a new record.

This is so the user knows that what they are entering is roughly in line with what has come before.

So for example if I was recording temperature every May, I would like a form that has a field called temperature and next to that field I would like to see last year's temperature.

Records:

Date | Temp
2014 | 20.5
2013 | 18.5
2012 | 19.0
2011 | 22.7
2010 | 15.2

So when I enter the record for 2015 I have a box that says: Temp and next to that box is "Last year was 20.5" or something like that.

View 2 Replies View Related

Modules & VBA :: Autofill Cell Based On Previous Record Value

Aug 26, 2014

I am trying to write some vba code to auto fill a cell's value based on the value of the cell in the previous record (In a datasheet form) i.e. if the value in record one was '1' and the down-arrow key was pressed then the value '2' should be entered into the new ext record

I have written some pseudo-code to show what I am trying to accomplish:

if keydown = down-arrow and current cell contents isnumeric then
Cval = current cell contents
if current record = last record then
create new record
move down 1 record
set cell value of new record to cval+1
else
move down 1 record
if cell value = null then set cell value of record to cval+1
end if
end if

View 14 Replies View Related

Modules & VBA :: Copy / Paste Field From Previous Record

Jun 22, 2013

It is a continuous subform (Names: Form = ClientUpdate / Subform = ClientUpdateSub.

All of the data implicated here is direct and in the subform's query table including the button we want to program.

(This is my example but it wont stay in columns in this "post box" )

IDNo App _ID App_Freq App_Date GetDates Action_Date
22 18 56 21-Jun-13 BUTTON 14-Jun-13
21 19 56 16-Aug-13 BUTTON 9-Aug-13

*

The GetDates Command BUTTON should generate the red data above, like:

Private Sub GetDates_Click()

Go to a new record
Go to the field App_Freq and fill it with:
Copy/paste the data from the field of the same name in the previous record
Go to the field App_Date and fill it with:
data based on this calculation using the PREVIOUS record fields: App_Date + App_Freq (which are days)
Go to the field Action_Date and fill it with:
data based on this calculation: App_Date (of current record now filled out - step above), minus 7 (days).
End Sub

That's it!

All the dates format is set to medium date. An error message should come up in case App_Freq is empty, for example

Also note that the data can be manually changed at any time and should not revert to its last calculation. The button only generate data into a new record.

View 14 Replies View Related

Forms :: When Clicked Form Opens To Blank Record And Won't Show Previous Records

May 6, 2015

I've recently decided to move a database that had all its information on 1 table and divided it into multiple tables.

Attached is the relationship as well as the form.

The issue I have is that when I click the form, it only shows a blank record with none of previous records.

Data entry is already set to NO. I'm wondering if it's an issue with my relationships, tblStudioDescription is the parent table and the others are child tables so I linked them with the ID and set referential integrity.

View 7 Replies View Related

Modules & VBA :: Completing Fields On A Form With Matching Data From Previous Records

Jun 4, 2015

I'm trying to make it a little further with my new call answering database at work.

Basically it consists of a main form that has a button leading to a call answering form for each business that we represent. it also has a text box that displays the number of the caller when the telephone picks up, the correct call answering screen is also popped by the telephone software and a macro whenever the phone is answered.

I've got code in place that automatically puts the date and time in the correct field and also copy the incoming telephone number from the main form into the caller number field on the call answering form.

I'd like to take this automation a little further now and get the form to autopopulate the caller details if that caller has called before (we get a lot of calls from the same people) so i'd like to make the form search the table it's linked to for the incoming phone number and to fill in the name, email, company etc... for the caller according to the previous record.

The code for the 2 forms i've currently got setup (the switchboard and one call answering screen) are as follows

Switchboard:-

Code:
Option Compare Database
Dim WithEvents MaxxCom As Metro_MaxxCom_CTI_COM_API.CTI
Private Sub cmd_onnet_Click()
DoCmd.OpenForm FormName:="On_Net_Communications"
End Sub

[Code] .....

View 8 Replies View Related

Modules & VBA :: List Box Current Record

Jun 18, 2014

I have a list box that my client goes through with vbKeyDown and vbKeyUp. When he finds the correct record he wants to do vbKeyReturn and capture the checktype code and description and have them placed in a check which is another form that is open. The following code does not work:

Private Sub List3_KeyDown(KeyCode as integer, Shift as Integer)
If KeyCode = vbKeyReturn Then
Forms!frmChecks![TRA{CODING =
Me.CurrentRecord.Column(1)
Forms!frmChecks![TRA:CODEDESC] =
Me.CurrentRecord.column(2)
DoCmd.Close adForm, "frmCheckType", acSaveNo
KeyCode = 0
End If

View 2 Replies View Related

Modules & VBA :: Save Current Form Record Only As PDF

Jan 17, 2014

I'm using: DoCmd.OutputTo acOutputForm, "Frm_EL_PL_Bulk_Send", acFormatPDF, outputFileName1...To save a form as a PDF. The issue is, it saves all the records in that set in continuous form, and I'm trying to get it to only save the record its on.

View 3 Replies View Related

Modules & VBA :: Form Won't Go To New Record On Current Event

Jun 3, 2015

I have a form with a subform. In the form's On Current event I have the subform's visible property set to false. There is a button that when clicked sets the subform's visible property to true. I want the subform to go to the first control in a new record which is a combo box. the subform is a multiple items form. I have tried the GoToControl in the subforms OnCurrent event, but it is not working. I get an error saying the database cant find a third form.

View 4 Replies View Related

Modules & VBA :: Copy Current Record From Recordset To Csv

Aug 4, 2013

I have a DAO.recordset called "rsSQLIn". This comes from a csv file by:

Code:
strSql = "SELECT * " _
& "FROM [Text;Database=" _
& strFolder _

[Code]....

While the validation runs a boolean keeps track of validated input and errored input.

After validation the validated input is dumped in the table.

Now what I want is de saving the errored record from "rsSQLIn" to be copied to a new .csv file.

The problem I have is that I cant seem to get the current record from the recordset "rsSQLIn". How do I reference this? I need the complete set of 24 fields being the same within "rsSQLIn"

View 3 Replies View Related

Modules & VBA :: No Current Record (3021) Error

Sep 18, 2014

I get this error when I delete more than one record consecutively.

Here is my delete code;

Private Sub Komut98_Click()
Dim blnLast As Boolean
'MsgBox call must return the value in order to be checked.
'If user says no then cancelling is not required. It is only required
' that the deletion command is not invoked.

[Code] ....

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved