ms Access '16 - Continuous form - OrderBy textbox value created with expression - ms-access

I have a form that shows the records from Table-A, it is a continuous form. I have a textbox that uses a DCount expression to count records from Table-B that share the same SOP-Number.
=DCount("*","[Table-B]","SOP = " & [SOP])
This works but I don't know how I would go about sorting that column based of the resulting values. The other columns are sorted thus:
" ORDER BY [FIELD NAME] ASC;"
So without a field I don't know how (or if) I can sort the form.
Could I create a RecordSet to store the values then sort by that field (I don't know if this is even possible)
Thank you
Dan
Access 2016 (365)

I'm not quite understanding why you won't know what fields you're pulling from Table B. But you can always order by the column number. So if you're looking to order by the first column, just put:
ORDER BY 1 ASC

You can't sort the recordsource but you can sort the form itself:
Me.OrderBy = "NumTasks DESC"
Me.OrderByOn = True
(assuming your textbox with the DCount control source is named NumTasks ).

You could change the datasource to
select ,DCount('''[Table-B],'SOP=' & SOP) from [Table-A]
order by DCount('*''[Table-B],'SOP=' & SOP)
This is not a good soulution i Table-A is big.

Related

how to capture grater than symbol parameter to build date field comparison in where clause for SSRS parameter report

new to SSRS report design. Although, I've used CASE statement before but not sure how to utilize in a condition where SSRS report needs to two parameters ( parameter symbol (>,<,=,%) and parameter date ) pull data from a dataset.
I'm wondering if CASE statement can be used to achieve this need?
Or any other suggestion that would work for this condition, will be greatly appreciated.
PS: I've not come across such example so far
I'm assuming that you want to parameterise the actual operator so the user can for example, choose < 1000 or > 50 etc...
If that's correct then you can do this as follows.
Assume we have two parameters
pOperator which has values of ">", "<" and "=" (note for the = option you will need to specify this as an expression ="=" or SSRS will think you have a blank expression.
pMyValue which will allow the users to type a number in
What you need to do is change the dataset query to be an expression, so something like this.
="SELECT Employee, Salary FROM myTable
WHERE Salary " & Parameters!pOperator.Value & " " & Parameters!pMyValue.Value
If you had used > and 30000 as your parameter values then this would return
SELECT Employee, Salary FROM myTable
WHERE Salary > 1000
You could also have a single parameter where the user can type the whole ">=15000" and then just replace the two parameters above with a single one.

Filtering A Lookup Field Based On Another Field

I have a lookup field in my table based on another table. I'm having trouble filtering those values based on another field that is entered prior to the field.
Is it possible to filter a lookup field based on another field?
EDIT
Let me try and clarify my original question, sorry about that. Ok, so I have a table1 that has the following fields: ID, Name, Logo.
If a user enters a specific name in the Name field, when they click on the Logo field, it'll only display those values associated that are similar to the name entered. Does that make any sense? If it does make sense, would there be an easier suggesion on accomplishing this task?
If you're talking about inside a table, the answer is "No". You can create cascading combo boxes on a form, but you can't base a lookup value in a field of a table off of a different field in that table (or the field in any other table).
Here is an example of how to handle filtering a combo box based on the value selected in another combo box:
I have the following form:
The combo boxes are named cboIntPN and cboManPN.
The Row Source for cboIntPN is set to: SELECT uniq_key, part_no, revision FROM inventor. The Row Source for cboManPN isn't set to anything.
When the user selects a value for Internal PN the following AfterUpdate Event is triggered:
Private Sub cboInternalPN_AfterUpdate()
[cboManPN].RowSourceType = "Table/Query"
[cboManPN].RowSource = "SELECT uniqmfgrhd, mfgr_pt_no FROM invtmfhd " & _
"WHERE uniq_key = '" & cboIntPN.value & "'"
End Sub
It sounds like he is having the same issue as me. I also wanted to filter a field in a table for data entry on another field's input and my conclusion is "it is time I stopped entering data manually in tables and begin to create Data entry forms. I was putting this task off until later, but if I don't do it now, I might make worse trouble for myself later.
Btw, what an old thread.

Filtering Microsoft Access Subform

I have a subform populated with different tasks. I want to filter them on DUE_DT with a filter that happens automatically. Some of the records have a blank DUE_DT, which I would like to filer out. I would also like to filter out records whose DUE_DT is more than 30 days past. I tried using VB but I haven't been able to find the appropriate syntax.
Here is some syntax for appplying a filter to a sub form:
Forms!MyMainForm.ASubFormOnMyMainForm.Form.Filter = "whatever your filter is"
Forms!MyMainForm.ASubFormOnMyMainForm.Form.FilterOn = True
"I want to filter them on DUE_DT with a filter that happens automatically."
I'm not quite sure what you have in mind there, but I wonder whether that could be handled by a WHERE clause in the subform's record source query.
WHERE DUE_DT >= Date() - 30
That would be automatic in the sense that the filter would always apply.
Note you don't have to add another condition to explicitly exclude Nulls (such as DUE_DT Is Not Null) because Null is not >= Date() - 30.
Try this in VBA, should work on every form or module you put it in:
Form_subFormName.Filter = "DUE_DT IS NOT NULL AND DUE_DT >= #" & (Date - 30) & "#"
Form_subFormName.FilterOn = True
Replace the subFormName in Form_subFormName with the name of your subform, but keep the Form_.

DSum returning number of rows instead of total value

I have the following code attached to a text box in a form:
=DSum("[subform].Form![POINTS]","ATTENDANCE","[subform].Form![EMPLOYEE NO] = [EMPLOYEE NO]")
Ideally this would yield the total amount of points accrued by the employee we are currently searching for. However, what I am getting is the total sum of rows in my table.
Does anybody have any idea of how I could get the total sum of the values instead of the number of rows?
Thanks
If you want to get the total from a subform, and your subform in in sync with the main one, it will be much more efficient to procede this way:
create txtTotalPoints textbox = sum(Points) in the footer of your subform
refer to that control from your main form: txtMainResult =subform!form!txtTotalPoints
Hide txtTotalPoints (or the footer itself)
That will generally be much faster.
As far as I know, the Domain functions such as DSum, DLookup, DCount etc. are used to lookup and return values from a table. The first argument is the field, the second the table, and the third is the criteria or WHERE statement that makes sure you get the correct set of records. Your first argument refers to a form's field. I think this is incorrect. Your first item in your WHERE statement is also a form field. I this this is also incorrect. You need to try something like this instead:
=DSum("POINTS","ATTENDANCE","[EMPLOYEE NO] = " & [subform].Form![EMPLOYEE NO])

Auto populate a combobox

Here i am again. I have 3 comboboxes on my form ie cmbPart_number, cmbPart_name and cmbEOnumber.
All i want to find out is how the cmbPart_name and cmbEO_number boxes are autopopulated when the user makes a selection from the cmbPart_number. What i have tried so far is adding part_name and EO_number in the row source SQL query and in the control source of cmbpart_name i have tried cmbpart_name(value)=cmbpart_number.column(1)
Any help with this is truly appreciated
You should be able to do this by setting the RowSource in the AfterUpdate event
Private Sub cmbPart_number_AfterUpdate()
cmbPart_name.RowSource = "...WHERE [PartNumber] = '" & _
cmbPart_number.value & "'; "
cmbPart_name.Requery
End Sub
Here's a walk through on different ways to implement cascading combo boxes in Access
I knew there had to be a simple way of doing this without digging deep into VB. My first combobox ie cmbPart_number, i have modified as follows - Row Source has all 3 fields in the SQL query ie SELECT part_number, part_name, EO_number from parts ORDER BY...;
I have modified the column count to 2 as Access always counts the first column in a table as number 0. So its Column 0,1 & 2 for all 3 fields. My column widths are 1";0"
Next I modified cmbPart_name's control source to read =cmbpart_number.column(1). Its row source has a SELECT statement SELECT part_number, part_name FROM parts, ORDER BY...
Column Count is 1 and Column Width is 0";1"
Finally for cmbEO_number, control source is =cmbpart_number.column(2). Row Source select statement is SELECT part_number, EO_number FROM parts ORDER BY...Column count is 1 and column width is 0";1"
This now works fine and any entry selected in the cmbPart_number box autopopulates the other 2.
Thank you all for your help.