Forms :: Syntax For Nested Aggregate Functions?
Feb 4, 2014
I have a problem with a nested arrangement of Right, DLookup and DMax functions.
The function is for a default value in a text control
=Right(DLookUp("[SampleNumber]","tbldat14A_MasterSampleList","[SampleID]=" & DMax("[SampleID]","tbldat14A_MasterSampleList"))+1000001,6)
I am trying to retrieve the last record from a field SampleNumber which is alphanumeric (e.g. "AK005434") and then add a 1 to it as the next SampleNumber. I had previously used a default value in the txtSampleNumber control as
="AK" & Right(1000000+DMax("[Clip]","[tbldat14A_MasterSampleList]")+1,6)
where [Clip] was a field I have calculated in the table to chop off the preceding characters. Adding 1,000,000 and taking the 6 right hand values and concatenating with "AK" gave me the answer, though it is a but primitive.
This all worked until the SampleNumber value got out of order and blocks of SampleNumber values came in that were then followed by blocks of numbers with lower values (say AK005001-AK005050 followed by AK002001-AK002050).
Now I figure if I just recall the latest entry by DLookup and criteria of DMax on the SampleID (Autonumber Primary key) I could get at the value. I have done this to some success using default values in a series of unbound controls like
=DLookUp("[SampleNumber]","tbldat14A_MasterSampleList","[SampleID]=" & DMax("[SampleID]","tbldat14A_MasterSampleList"))
to get the SampleNumber I require, then a Right function to trim in another unbound box and then use that last unbound box as the default value for the txtSampleNumber control that is the entry for the data table. However, the unbound control box is only valid for the first record and does not update. So, I added a macro that closes the form and reopens it. This all works but is a bit agricultural. I would like to do a single nested function to the default value of the txtSampleNumber control box. Is it possible to nest Right, DLoopkup and DMax into one statement?
View Replies
ADVERTISEMENT
Mar 20, 2014
I have searched to find the correct syntax to refer to a combo box control on a nested subform. All the examples I've found Access 2013 will not recognize or find the appropriate control.
I have a parent form called IncidentDetails. On that form I have a control called ctrlLogDetail. Within that control is a form called sfrm_LogDetail. On sfrm_LogDetail, I have a control called ctrlType which houses a form called sfrmType. On sfrmType, I have a combo box called cboType. I need to be able to place the cboType choice into a query to filter records for another combo box on that same form. the query works appropriately when I have sfrmType open, however as soon as I try to call the query from the IncidentDetails form, Access cannot find the cboType control.
I've tried multiple variations of the syntax to call to cboType that I've found online. I found a very useful reference from BTA Development: however the syntax there will NOT work in Access 2013.
What is the appropriate syntax would be to get to my control within my 3 deep nested subform? I'm working Access 2013 and won't have a choice regarding Access versions.
View 5 Replies
View Related
Aug 29, 2005
I was wondering if anyone can help me: I have for example Pupils that are being entered into a table (called log). A query then counts the number of entries for each pupil I then want it ONLY to show the pupils that have been entered in 10 times on todays date (using DATE()).
I know this doesnt work but this is what I want to do:
SELECT log.pupilNo, log.Forename, log.Surname, Count(log.pupilNo) AS Demerits
FROM log, Tally
WHERE (log.Date)=Date() AND COUNT(log.pupilNo)>9
GROUP BY log.pupilNo, log.Forename, log.Surname, log.pupilNo;
Apparenty you cannot have an Aggregate function in a where clause.
Does anyone know a solution, any help would be appreciated
Cheers
Bikeboardsurf
View 2 Replies
View Related
Oct 16, 2006
Hi,
Is it possible to add a calcualted field to a query that already uses 'sum'?
I want to take the value returned by sum and add the value of another field to it.
Any help will be very much appreciated.
B
View 12 Replies
View Related
Jun 7, 2007
Is there any way to lookup items using DLookup or other functions that will return an array of values not just the first value found. Example: I have three employees in a complaint query. I am using Dlookup to identify them on my employee form. When I get to the same employee/employee id on my employees form, I have a label that flashes red to flag me that this employee appears on that complaint query. The problem that I am having is that it only flashes for the first employee found in the query, and the label only flashes for that one person. I would like the label to flash for the other two employees because the function should see that they are in the query results as well. Help please?!!!
View 2 Replies
View Related
Jun 21, 2005
I know SQL well enough, but I cant seem to get my query to work. Basically, I am trying to display a series of posts, with the number of comments on the side.
I have two tables, Entries and Comments, which look like this:
Entries
---------
IDTitleContent (memo field)
1CatsSomething about cats here
2DogsSomething else about dogs here
3RodentsMy pet rat runs in a wheel
etc.
Comments
--------
IDPostIDComments
11My cat's name is mittens
21I taught my cat how to throw a curve ball
33Rats like squeak toys
42Nobody likes dogs
53Bunnies make good pets
61Cats are witches in disguise
Comments.PostID corresponds to Entries.ID on a many-to-one relationship.
I want to run a query that will join the number of comments (which is a Count of each row in the Comments table where Comments.PostID = Entries.ID) to the existing table, so that it will look like this:
Entries (with #ofcomments joined)
----------
IDTitleContent (memo field)#ofcomments
1CatsSomething about cats here3
2DogsSomething else about dogs here1
3RodentsMy pet rat runs in a wheel2
etc.
Usually, this would be a really simple SQL statement, but as I am using a Memo field, I am getting a "cannot use Memo field in aggregate function" error.
I'm not sure what to do, any help would be appreciated :)
View 4 Replies
View Related
Mar 22, 2013
I have the following query. I got an error when I ran it.
Code:
SELECT COUNT([encounter_number] WHERE status = 'Death')/ COUNT([encounter_number]) AS Death Ratio, tbl_test.facility_type AS Type,
FROM tbl_test
GROUP BY tbl_test.facility_type;
I think the problem is that first WHERE clause inside.
View 2 Replies
View Related
Apr 3, 2007
Alright, I've got all the pieces to this puzzle, I just can't fit them together properly. I have two tables, tblTickets and tblTicketNotes. They are in a one-to-many relationship, there can be multiple Notes attached to a single ticket. I am trying to set up a query that will pull the first (earliest by date) note for each individual Ticket. Here are the fields from each table that would be of concern here:
tbTickets
TicketID - Autonumber - Primary Key
Issue - Text - I will be using this later as a criteria to limit with, but not neccessary
tblTicketNotes
NoteID - Autonumber - Primary Key
TicketID - Long Integer - This is the foreign key of the relationship
DateStamp - Date/Time - This is the Note Date, I only want the first (earliest date) one
Content - Memo -This is the note information I want
So all I want is the Content of the first/earliest Note for each individual Ticket. I know this should be fairly easy, but I am at a loss.
View 2 Replies
View Related
Jun 26, 2007
I'm having a problem with queries, and I can't seem to find a solution in books - I looked through about ten of them and none of them addressed the problem. This may be because it has a painfully obvious solution...
A little background:
I am designing a database for a debt-collection law firm. One of the functions it must have is to keep track of various different sorts of financial transactions which can pertain to a given debtor (ie, a received payment, a cost expended, and a few other things).
The problem is that, in generating reports, I need to use queries to find several sums of only those transactions which fall into specific categories (for instance, to calculate the amount a debtor has paid against his balance, it needs to sum only those entries which are both linked to that debtor's ID number and whose type field reads "payment", and then subtract from that those entries whose type field reads "cost"). The problem is this: not all debtors may have "costs" entries, and when there are none, the report comes up blank with a single "#Error" written in the name field and nothing else present.
I believe the problem is that the Sum aggregate is returning a null value when the query finds nothing that meets the criteria. I have been unable to find a way around this; the Nz() and IIf() with IsNull() functions don't seem to be helping.
The query runs as intended when there are entries for every relevant type; however, it is undesired to have to enter a "payment" of $0, "cost" of $0 etc for every entry just so that this function works.
Is there anything I can do about this? Any input would be appreciated, as I'm fairly inexperienced with the use of Office Access. (If it matters, I am using Office 2003).
View 2 Replies
View Related
Jul 8, 2012
i need domain aggregate functions to count the occurrences of specific value in a field, and when it exceeds 1, display null. or 'group by' subqueries with count() to see if you should populate the field or not.
View 3 Replies
View Related
Aug 8, 2005
I am working on a report in Access2000 which is getting information from several tables via a number of queries.
I am using nested IIf() functions to combine text formatted data in a calculated query field before using it in a report.
One such IIf() function is
Desc_col: IIf([HOVR - UDP].[SERVICE] Is Not Null,[DA] & " " & [SEQ] & " " & [TYPE] & [MO] & " " & [SUB] & " - " & [HOVR - UDP].[SERVICE],
IIf([MinOfCCT] Is Not Null,"I/O DIST CAB " & [UDP - JC CIRCUITS-05-F].[PWR] & " - CCTS " & [MinOfCCT] & " thru " & [MaxOfCCT],IIf([DESCRIPTIO] Is Not Null,[DESCRIPTIO],"Spare")))
When I have tried to do the same thing with date fields it does not work. The function is fine as long as it is not nested.
That is
Rev_col: IIf([Rev_HOVR] Is Not Null,[Rev_HOVR],"")
and
Rev_col: IIf([Rev_Elec_equip] Is Not Null,[Rev_Elec_equip],"")
both work.
But when I combine them into a nested function
Rev_col: IIf([Rev_HOVR] Is Not Null,[Rev_HOVR],IIf([Rev_Elec_equip] Is Not Null,[Rev_Elec_equip],""))
I get an error message "! Data type mismatch in criterial expression"
There is no data mismatch in the original tables from which the information was extracted. The dates are all in DATE/TIME and set to "General"format in the tables.
I am wondering if I will have to use Visual Basic function to combine these fields. However that poses a problem. When I've looked at this I find that runtime VB is no longer available in Access and I do not want to go out and buy it on the offchance that it will work.
Can anyone tell me if there is another solution to my problem?
View 4 Replies
View Related
Aug 29, 2007
Hello,
I'm new to working with Access Iif statements. I'm attempting to change data values in an existing table for column named "Status." Some of the data in this column has the correct value (Active) that needed represented, while the rest is populated with either a "J" which is Active or "T" which is inactive. I needed an update query that will ignore any values that are already "Active," and convert any values that are "J" to Active and values that are "T" to "Non Active." Any help would be greatly appreciated. Below is the function I have written that's full of syntax errors:
IIf(([STATUS] T,"T") = "T", then "Non Active"), IIf([STATUS] J,"J") = "J" then "Active"), else Active = "Active"))
View 11 Replies
View Related
Jul 23, 2007
Hey,
I am working on my first access project (please be patient and try to explain like to a child). My problems however are past the basic level so please bear with me ....
I am working on a datbase which deals with laboratory data from patients which have different date stamps - ie. each record has a 'valid time' (time of blood drowing) a 'transaction time' (time of entry into the DB) and 'delete time' (deleted recordes are just given a date and not really deleted).
The idea is that the user should be able to watch the status of the DB at different past dates (ie what did the doctor know about a patient blood tests a month ago when he made the decision to give him a medication which eventually harmed his kideneys). The user should also be able to change values of records, delete records (which means to add a date to the deleted date field) and to add new records.
I want to do it all using one form.
Things I have done so far:
1. Query by form which locates a specific record (Main-Form & singleRecQuery)
2. A subform in Main-Form which displays the results of singleRecQuery (Single-subform). The query and subform aer updated by a macro once I enter all the data into main-form.
3. A qury by form derived from Main-Form which locates a range of values (Range-subfrom & Range-Query)
My problem spans both forms and queries (so I am posting in both forums):
1. I want to create an update query that will draw its data from Single-subform (the form which displays the results of singleRecQuery). I have created the qury without a problem but the fields in the form are locked for entering data (maybe because they are bound). Is there any way to enter data in such a form which is based on a query and then use the new data in another query ? (I tried allowing data entery in the forms properties but it deos't work).
2. I have tried to put a criterion in the queries on the "Delete Date" field so that the quries will not display the deleted records (I have tried "is null" "is empty" and "is missing") but when I run the query with these parameters I get no records back.
3. In the form I have a command buton which runs a macro that runs the qury and then update dthe subform. Is there a way to get this button to run different macros after different events in the form or do I have to add a button for every specific task I want.
4. As I have mentioned the Main-fom is supposed to run 3 differnt queries and display the results on the same form. I know how to make a subform invisable but is there a way to place all three result subforms in the same spot ?
Sorry it is so long
Thanks
EJ
View 1 Replies
View Related
Jun 19, 2014
I have a main form (frm_main) in which I have a subform as a datasheet (frm_sub1).In the first sub form I have a second (nested) subform (frm_sub_sub2) as a datasheet as well.
On the main form I have an unbound text box which gives me the value of the ID field in the nested subform (frm_sub_sub2).In the main this works well, however, I hit a problem at a particular point.
If I expand an entry in the first subform (frm_sub1), then, in the main form (frm_main) I get the first ID value from the corresponding records in the nested subform (frm_sub_sub2) as expected, which then changes as I scroll through the expended records.
However, if I then expand another entry in the first subform (frm_sub1) without collapsing the previous entry, the ID value shown on the main form (frm_main) from the nested subform (frm_sub_sub2) remains the same and doesn't change to the currently selected record. Even if I then collapse the first selected entry on frm_sub_sub2 - the original ID value still remains on the main form (frm_main).
View 1 Replies
View Related
Nov 23, 2013
I am placing a breakpoint within a function that runs after an update. The function runs, but the break does not happen. Is there some setting that can be adjusted that allows this to happen?
View 2 Replies
View Related
Nov 23, 2013
I am placing a breakpoint within a function that runs after an update. The function runs, but the break does not happen. Is there some setting that can be adjusted that allows this to happen?
View 6 Replies
View Related
Mar 19, 2013
Multiple IF functions in a form. I have a button that on click will print a report if certain fields in the form have data in them. If not, a msgbox pops up to let the user know that data must be filled and then sets focus on whichever field needs data in the form. There are many IF statements, and they all work fine until I get to a certain one then the remaining IF does not continue.
Here is some code:
If IsNull([Alert]) Then
MsgBox "An alert time is required." _
, vbCritical, "Data Required"
Me.Text591.SetFocus
Exit Sub
Else
If IsNull([Enroute]) Then
[Code] .....
The next IF argument will bring up the msgbox when there is no data, thats great. However, when the user fills in the field and continues with the button click to print the report, the button does nothing.
Here is the next IF, the one with the problem:
If IsNull([Combo608]) Then
If IsNull([Combo620]) Then
MsgBox "You must select either a planned event or an emergency event." _
, vbCritical, "Information"
Me.Combo608.SetFocus
Exit Sub
Else
How to get it to work, to continue with the remaining IF arguments after this one (there are several more)?
Or are there a better way to code this and not have the many IF arguments?
View 2 Replies
View Related
May 9, 2014
I have a form in my Access database that has 3 input boxes by which a user can locate a record by. The problem I am running into is that I can not get a nested IF statement to work properly to first check which of the search boxes are filled in and second search by whichever is filled in. I have come up with the following code that seems to be only searching by the first input box. If the first input box is blank it does not move to the second or third numbers so I imagine there may be something wrong with the order of my IF statement or the syntax is off.
View 14 Replies
View Related
Aug 3, 2015
I've attached screenshots of the table relationships and some nested forms that I need to discuss in my database.
If you look at the forms screenshot you'll see I have a main form "business/cmc issues" that uses a combo box to select a business name; nested into that I have a second form "policy issues log" that holds details of policy issues about that business; then inside that I have a sub form "issue updates" that records brief details about the actions carried out in trying to resolve each policy issue.
The same policy issue can affect more than one business (because of a relationship between the two companies etc) but still needs to be viewed separately. So for example in the business selector combo box I might have business "ABC". In the policy issue it might say "doesn't pay on time". The "doesn't pay on time" issue might also apply to business "123" and so if I picked that business from the combo box you'd see the same policy issue.
Because it's the same issue for two separate businesses, the actions carried out will be the same, so what I want to do is, after a new action is carried out (where relevant) to be able to click a button that would run some code that copies the actions entered in the sub form for business ABC and pastes them into the sub form for business 123 where the product area and policy issue are equal. This is to avoid having to enter the same data twice.
View 3 Replies
View Related
Aug 8, 2013
How do I activate functions mouse functions in a field? I want to click the right key of the mouse when I'm in a field within a form so I can cut, copy, and paste.
View 2 Replies
View Related
Jul 25, 2014
i want to add a control in that form that sums up and aggregate all the values of field called [amount] based on the value of [Name_Patient] as criteria
View 2 Replies
View Related
Feb 24, 2015
Me.txtversion = "Ver:" & " " & DLookup("[txtVersionMajor] & " - " & [txtVersionMinor] & " - " & [txtVersionRevision]", "tblVersionInfo")
What's wrong with my syntax ? It's the "-" part that is the problem.
View 3 Replies
View Related
May 15, 2015
I need to add HolDte and make it also use HolidayDate as it's criteria.
PHP Code:
strSQL = "INSERT INTO tblHour (WorkDate,Hours,HolDay,EmployeeID) " _
& " VALUES (#" & Me.HolidayDate & "#," & Me.txtHrs & ",True," & Me.EmployeeID & ")"
View 7 Replies
View Related
Apr 11, 2014
I have table [table1] which have 4 fields
EMPID - primary key
EMPFirstname
EMPLastname
EMPDOB
Input box as txtempid as string
I am trying to learn how I to display other field based on one field in my case last three field based on EMPID
I am actually getting syntax error when I dry to display DATE Field
Following are my attempts
Dim Verfirstname as string
Dim Verlastname as string
Dim VerDOB as date
Verfirstname = dlookup("[EMPfirstname]","table1","[EMPID]='" & me.txtempid & "'")
Msgbox Verfirstname
works fine. But when I use for Date, I am getting syntax error
VerDOB = dlookup("[EMPDOB]","table1","[EMPID]='" & me.txtempid & "'")
Msgbox VerDOB ---- now I am getting syntax error
I tried to understand over net and I believe i need to used with "#" before and after the date field but my criteria...
View 1 Replies
View Related
Jun 24, 2015
Can I use the Like command in an If Then statement? I'm getting a syntax error
If [Primary1Name] Like 'PO*' Then
MsgBox "You cannot use a post office box address. Use a residence address.", vbOKOnly, "Incorrect Address Information"
DoCmd.GoToControl "Primary1Address1"
Else
End If
View 3 Replies
View Related
Apr 1, 2014
I have a program that has a "GC" Button that I click on which takes me to a General Contractor Form. It works perfectly unless the Firm has an apostrophe in it's name. For example "D'Agostino". (refer to attached DAgostino1.jpg). When I click on the GC button, I get the attached Syntax error, (Syntax on DAgostiono.jpg).
The third attachment (GC Firm Button Code.jpg) shows the VBC for this button.
how to fix this error?
View 7 Replies
View Related