How to get min/max values on form that returns multiple records - sql

I've got a form that returns multiple records from a table. Each of these records has a field indicating what the measurement was and the measurement's value. My form's record source pulls the appropriate ID's set of measurements and values, and then I want to write each of these measurements to different text boxes on the form.
The problem is that I'm also keeping track of the date this data was updated, and want to include only the data pulled based on the "date updated" selected at the top of the form.
When I go to pull the measurement value into a text box (with something like max(iif(Measurement="Acidity", [Value],[Null])) I get #Error all down my form. This had been working earlier today, and as I've been developing the form something changed and now it no longer works (everything but the date returned is saying #Error). I've set it to Requery when the form loads and whenever the date selected is changed.
EDIT:
This form is actually a subform of another main form. The main form has a control called MemberID which a user can use to select the Member they want information about. This is based on a query that pulls from a table the information related to that MemberID (one row per MemberID). When the form loads, the query behind the main form needs to be requeried to get the data for the selected MemberID.
Then there is this subform causing the problems. On this subform is a "Data Updated" drop down box, which lists the possible dates that the data was updated. When one chooses a particular "Data updated" in the drop down box, this chooses the latest data for all the data measures up to that date selected. This means the form's record source pulls about 10 records in my case.
Then, on this subform I try to layout these 10 records' values in different text boxes. So, in my acidity case above, I would say iif(Measurement="Acidity", [Value], Null). Because there are 10 rows returned, I will end up with 9 Nulls and 1 value, and to get that value I use the max function, so the text box's control source reads: max(iif(Measurement="Acidity",[Value],Null)).
The strange thing is this code was working this morning, until later this afternoon when I was filling in the remaining text boxes with similar code, and then it stopped working. I had also renamed the boxes from Text71 to more relevant names, but none of these are referenced in the code.

Related

MS Access Subform adding multiple rows

I have a form that I use for memo generation which I just added a new subform to which handles contract info. It is a small table which only has the PurchaseID (linked to the main table) and then the contract fields shown as text boxes/combo boxes.
My Issue: Originally what was happening was when a user didn't click into the sub-form shown, no row would be created in the Contract table. If you look at the picture, when the form loads the "PurchaseID" field is populated because it's an autonum linked to the main table. However even though that field is populated, if a user doesn't physically click into the sub-form, no row gets created. I just want the blank row with the default options to be added to the table.
My attempt to fix it:
What I tried doing to fix this is on the event "On Current", I wrote 1 line of code that just sets the value of the combo box to a value. I think this sets the sub-form as a focus and it does end up creating the record. The problem is, now whenever the form loads, it initially tries to add a blank row with the ID of 0 to the Contract table, essentially making a duplicate blank row every time the form opens. I think the reason is because the "On Current" event is happening before the "PurchaseID" field is linking to the main table, resulting in a PurchaseID of "0" continuing to duplicate when the form is opened.
What I need:
Looking at the picture below. How do I make it so when a user does not click in that subform box when going through everything, a new record is added to the sub-form table with the default values selected (procurement/notrequired/etc.).
Picture of form. Sub-form that has issue is circled.

Access 2013 query only pulls the first record

i'm hopeing someone will be able to solve this. I have a combo box which shows the records that are available to view. Upon selecting a record, my query updates without any problem. I tried to use this query within a subform however, for some reason, only the first record in the data set is shown upon selection. When I select anyting else from the available options, the subform doesn't change. However, when i re-select the first record, it shows.
The weird thing is, that when I change the drop down box to say the 2nd record & run the query itself, the desired record shows within the query designer.
To explain further: the combo box is called searchByAcc_cb. This is set so that it retrieves the account name & various other fields from the same table. Below that, there is a subform which is set to requery once another account from the drop down box is selected. When I select the 1st account, the record shows. However, upon selecting the 2nd account, 3rd, etc, nothing shows. I can then re-select the 1st record & i see the account information - so i know it's not a problem with the form updating.
The other strange thing is that upon selecting another account within the drop down box & then running the query from the query designer, the account information is retrieved for the 2nd / 3rd 4th record within the datasheet view. So, i know it isn't a problem with the query.
Any ideas on how to resolve? I've tried deleting the subform & re-inserting it (ensuring that the names match).
For anyone else struggeling with the same problem, I managed to resolve it: You need to delete any reference to the child / master fields within the subforms properties.

MS Access How to make a field in form invisible if it is empty

I am trying to make a filed in my form become invisible if it's value is empty.
What I have is a form with individual records from a table, this has a sub-form which is linked by an ID, and it displays the results of a query.
This has three fields ones is the ID, a number and third is a date, Not all records have a date and therefore for the ones that do not have one I want to completely hide the date label and the empty text box; and make it appear only when a date is specified.
I'm guessing I might have to use some kind of WHILE statement in my query but I'm not sure whether that's right and how to do it.
I would appreciate your advice on this.
Thanks
You can add this code to the subform current event:
If (datafieldname & "") = "" then
datafieldname.visible=false
else
datafieldname.visible=true
End if
Where datafieldname is the name of the data field on the subform. This will only work if your subform layout is not tableview

Continuous form with dependent combo boxes

I have a continuous form that has a dependent combo box on it. I have the dependent working individually for each row/record BUT the dependent combo box is blank unless it has focus then it shows the saved data so what I did was placed a text box over the data portion of the combo box and set its control source to the same field as the dependent combo box and required and it worked great BUT unlike a combo box which would show the name it shows the saved data which is a ID number so I guess my question is how can I show the name and not the data?
Thanks!
You'll need to clarify, but if the combobox is bound to a field of the form, and its RowSource displays two columns - say an ID and Name - then giving the first column a width of 0 will persuade it to display the Name, rather than the ID.
You will also need the Column Count to be 2 (or more) and the Bound Column to be 1 (the ID). Then set the Column Widths to 0cm;2cm (add more values if more than 2 columns).
Added
Remove this criteria from your cobmobox's Row Source:
[Forms]![frm_DelayMachineOutputSubform]![cboCategory]
It is not needed. The ActivityID (and the CategoryID) are obtained for each row in the form.
Remove these lines from the Current event as well:
Me.cboActivity.Requery
Me.txtActivity.Requery
again, they are not needed (and cause the flicker). Better yet, just delete this event-code.

Combo Box Column Count culls data?

Basically, I have a combo box that I'm using to select a record. That combo box then populates several textbox's that are found on my form based on the ID. See the two images:
.
I'd like the combo box to show the first two columns in my query, which consists of 16 fields. The Abbreviation and the Name, to be exact. However, I found that if I hid the fields in the query or if I limited the column count of the combo box so it only displays the two, it actually culled the data so that the textbox's would not find it (thus be blank).
My question is, how can I just show the first two columns of the combo box yet still use it's ID to reference all sixteen?
Query
SELECT Tradeshows.tradeShowAppreviation,
Tradeshows.tradeShowName, Tradeshows.tradeShowID,
Tradeshows.tradeShowWebsite, Tradeshows.tradeShowLocation,
Tradeshows.tradeShowDateStart, Tradeshows.tradeShowDateEnd,
Tradeshows.tradeShowBoothSize, Tradeshows.tradeShowShipDate,
Tradeshows.tradeShowAudience, Tradeshows.tradeShowFocus,
Tradeshows.tradeShowMailer, Tradeshows.tradeShowDoorDrop,
Tradeshows.tradeShowProductFocus, Tradeshows.tradeShowAttendees,
Tradeshows.tradeShowMembers, Tradeshows.tradeShowMemberships
FROM Tradeshows;
Do not change the column count, change the column widths.
Column width: 0cm;2cm;1cm;0cm
And so on.
it should not be difficult to only select the relevant columns. You could post the Row Source property of your combo.
It seems to me that you should be binding you table to the data source TradeShows and using the wizard to create a combobox that finds record.
You can do this by selecting the table Tradeshows and choosing either create form or form. You will now have a form with the RecordSource property set to TradeShows. Next, choose to add a combobox to the form, ensuring that you have selected the wizard (the magic wand button is highlighted). You will be given the option to "Find a record on my form based on the value I select in my combobox". You can choose this and step through the wizard. When you get to the step where you choose fields, make sure you choose the TradeShowID first, and then the name and / or abbreviation. If TradeShowID is the primary key, as it should be, the column will be automatically hidden in the next step, which will show the fields selected.
The result of these actions will be a combobox with the following properties:
Row Source : SELECT [Tradeshows].[tradeShowID], [Tradeshows].[tradeShowName],
[Tradeshows].[tradeShowAppreviation] FROM [Tradeshows];
Bound Column : 1
Column Count : 3
Column Widths : 0cm;2.54cm;2.54cm
You will also have [Embedded Macro] in the After Update event (2010 and possible 2007) or [Event Procedure] for earlier versions. The wizard code is pretty poor, but that is another days work.
If you still wish to do all the work of setting each control to the (possibly changing) column order, you can follow a similar lay out for the combo, setting counts and widths appropriately.