Auto populate a combobox - ms-access

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.

Related

row labels are missing on new page RDLC reports

I have RDLC report on which I have multiple rows for every employee, I hides employee names after 1st row, right!
Now I have a issue when same employee's rows goes to next page it shows widowed records (without employee name).
To hide employee name on next rows I am using this code:
=IIF(Fields!Name.Value <> Previous(Fields!Name.Value), Fields!Name.Value, nothing)
I also tried adding new group, and got rank from stored procedure, but nothing helps.
Is there any way to get that if the row is 1st row of page?
Or any other way to achieve the same?
Thanks in advance
Finally I Resolved this issue by 1st adding group on top level with this formula
=CEILING(RowNumber(Nothing)/50)
and in the text box this group returns me row number according to each page, So,I updated my formula for text box to:
=IIF(Fields!Name.Value <> Previous(Fields!Name.Value) OR RowNumber("PageRowGroup")=1, Fields!Name.Value, nothing)

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

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.

MS access2013 datasheet shows display values, but listbox only shows ID

I have a table named "customers", and a table named "cases". These relate to real estate transactions. On the table "cases" I have a field for "other party", which lets you enter a new customer or pick from an existing one if we have already had that person in our database from a different transaction.
I have created a form with a listbox so I can search all the case records via the customer and other party fields (I also show some other info about the case but am not needing to search that info). In formview the listbox shows the customer name, but only shows the ID number for the other party. When I go to the rowsource, buildevent, and see the query in datasheet view, the records display the way I want them to -by name, not showing ID numbers.
Why won't it display correctly on the listbox??? Please help! I have spent way to many hours trying to figure this out :( This is my first time using access and I am just figuring it out as I go.
this is the SQL from the query in the listbox rowsource:
SELECT Query3.Customers.ID, Query3.[Last Name], Query3.[First Name], Query3.[Other Party], Query3.[Property Address], Query3.[Assigned To], Query3.Lawyer FROM Query3;
and this is the SQL from Query3:
PARAMETERS [ [forms]]![FRM_SearchMulti]![SrchText] Text ( 255 );
SELECT CasesALL.*
FROM CasesALL
WHERE (((CasesALL.[Last Name]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*")) OR (((CasesALL.[First Name]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*")) OR (((CasesALL.[Other Party]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*"));
Listboxes and combo boxes have a hidden column feature, usually a primary/foreign key of underlying table. Users generally do not know which primary key they should pick, hence the connecting name/item displays for their selection. Your situation sounds like the key is not being hidden but displaying and with two columns designated, you do not see the Other Party field.
To fix, under Property Sheet / Format Tab of the listbox, adjust Column Count and corresponding Column Widths according to your query (i.e., recordsource of listbox). As shown below the first column of query is hidden with 0 inches of display while the next two fields will display at 2 inches:
Column Count: 3
Column Widths: 0"; 2"; 2"
...
List Width: 4"
Be sure column widths add up to your List Width or there will be cut-offs. Also, inches are automatically added when you enter numbers. Finally, do note the data value of the listbox will be whatever is designated in Bound Column under Property Sheet / Data tab:
Bound Column: 1
Usually, the bound column is the hidden field or it wouldn't be hidden or used!
You probably miss to set columnwidth(s) of the listbox to: 0

List box and Option group filtering 3 different rows in MAIN list box in MS Access 2013

I've been struggling with the following for a while and would be more than happy for some brainpower ;)
I have an Advanced filter form, which filters through orders via many different filters, currently the one that I can't make function is the following:
I have 4 controls on a form (all unbound):
ogProductType - option group that allows you to pick from 3 types of products
lbAllProducts - list box displaying all types of products. It has 2 rows, and gets filtered by tbSearchProducts which searches by the name of the product, but the lb is bound by the first row which is the product code. The filter is done by inserting criteria into the name row:
"Like "*" & [tbSearchProducts] & "*"".
tbSearchProducts - text box for searching the product by name. Has requery for lbAllProducts OnChange.
Main orders list box - lbOrders - which has many rows. The ones we care about in this case are ID; eProductCode; fProductCode; kProductCode. It is supposed to display all IDs of all orders where the filters are true (all orders where type 1 product is bought). In the query builder I have the following code as criteria for each them:
In lbOrders:
for eProductCode row
IIf([ogProductType]=1 And Len(Nz([lbAllProducts]))>0;[lbAllProducts];"")
for fProductCode row
IIf([ogProductType]=2 And Len(Nz([lbAllProducts]))>0;[lbAllProducts];"")
for kProductCode row
IIf([ogProductType]=3 And Len(Nz([lbAllProducts]))>0;[lbAllProducts];"")
I want the Main list box to be filtered depending on what type of product was chosen (eProductCode is chosen with the option group set on First option = 1; fProductCode = 2; kProductCode=3), but ignore the other 2 rows totally. Sadly, with that false statement saying the criteria for the field is "", in case it was not chosen via the option group, it doesn't work.
How can I stack 3 criteria, all taking values from the same list box, but only if option group is the right on, without them interfering with each other?
I tried with "*" in false and it doesn't work...
Any ideas?
I've solved it :)
You simply never use the criteria to filter the 3 rows... You just use the field itself to load the proper row that you need and put in criteria...
Here is the code for the field:
Expr1: IIf([obProducts]=1 And Len(Nz([lbSearchProduct]))>0;[tblOrders]![еProductCode];IIf([obProducts]=2 And Len(Nz([lbSearchProduct]))>0;[tblOrders]![fProductCode];IIf([obProducts]=3 And Len(Nz([lbSearchProduct]))>0;[tblOrders]![kProductCode])))
And in criteria for that row I set the list box that has the bound column for product code lbAllProducts

Hiding Rows with Blank Fields in Access Subreport

I have a subreport, ExpenSubrpt, in Access 2010 that’s basically a table with two columns: YearNo, and Amount. These values are taken from another table, Expenditures. Long story short, some records in my database have rows with no YearNo. What I want to do is to hide the rows that don’t have a YearNo, ie. YearNo is blank but there is something in Amount. For example:
YearNo Amount
20
1 50
I want the first row to not be visible. I’ve tried putting
"[YearNo] <> " " AND [YearNo] IS NOT NULL"
into the Data -> Filter tab, but it gives me a syntax error (missing operator). When I removed the space, the error goes away but it doesn't filter, either. I've also tried calling a query by using the OnLoad event.
Private Sub Report_Load()
DoCmd.OpenQuery "Expenditures Query"
End Sub
Query:
SELECT Expenditures.YearNo, Expenditures.Amount
FROM Expenditures
WHERE (((Expenditures.YearNo) Is Not Null));
However, this doesn't work either. I’m not really sure what to do from here, or if there’s a better way to filter this form. Any assistance would be greatly appreciated.
You might want to change your query to have the "Not" before the field name, like this...
SELECT Expenditures.YearNo, Expenditures.Amount
FROM Expenditures
WHERE ((Not(Expenditures.YearNo) Is Null));