Access Combobox read from other table & generate report - ms-access

Hy all ,
I'm making an access 2013 databases application , for my work place with the scope to generate automatically some documents based on some combo box selections.
So in order , to be much more specific , the main form have :
one combo-box selection for truck number (cboNr_Auto) which reads from table "Advanced Conditional List" and fill auto text boxes for displaying name of driver , license number , etc... ( working well with afterUpdate event)
one combo-box selection for code of trash (cboCod_Deseu) which reads from table "Categorie_Deseuri" and display the name of the trash in text-box "txtDenumire_Deseu" ...(not working)
date pickers for loading and unloading dates- working well
text box for manual entry of weight - working well
My questions are next :
how can i make my combo-box selection "cboCod_Deseu" to display values in text-box from the table "Categorie_Deseuri" in my main form ?
how can i generate an report based on my combo-box selections , date pickers and manual entry for the weight field via a pushbutton?
Thanks

let say you have combobox with a recodsource and this recodsource returns 3 column.
Now if you want to set the textbox based on the selcted value of combobox than you can set the textbox controlsurce as below.
=[Combo0].[column](1)
'Combo0' is the name of combobox.
For report based on the different criteria.
first of all create a query for the report and change this query based on your criteria.
Below is the small example how you can acheive this.
Dim query_1 as string
query_1 = "Select * from Table1 where DATE = #yourdate#"
CurrentDb.QueryDefs("Report_Query").sql = query_1
Report_Query is the name of the query which you have saved earlier. open the report based on this.

Related

MS Access using ApplyFilter from Macro Builder with combobox shows input parameter box

This time I'm trying to work on an MS Access application. I have a split form populated using a SQL query. Now I want to filter this form using a combobox which is located in the header of the form. This CB is also populated with a SQL query:
SELECT DISTINCT [ConsultQ].[ClientName] FROM ConsultQ;
I have added an embedded query to this Combobox which should filter the form. The values shown in the Combobox are correct. But when I select a value from the box a popup show which asks me for input.
The ApplyFilter action is set to:
So, apparently, the ApplyFilter action cannot retrieve the selected value of the Combobox. What am I doing wrong here?
When I enter a name in the input box, the filter is applied correctly. So the filter works, but I cannot set the filter using the selected combobox value.
It must be something simple, but I cannot find it.
I'm using MS Access Office 365 version.
Remove the [Text] property. You want [Value] and [Value] is the default so doesn't have to be explicitly referenced.
Also need full path reference to combobox.
Forms!yourformName!cboClient
However, really should use ClientID to filter records. If the combobox has ClientID as first column and first column is set as the BoundColumn, then combobox value is ClientID, not ClientName.

Can't select combobox entries after applying filter to column

I have a column full of comboboxes. The comboboxes work fine on their own.
But if I right click on the column and apply a filter, e.g. sort alphabetically, the comboboxes still show with the correct entries, but I can no longer select another entry in the box. E.g. the box says "supplier", but I want to select "customer". Clicking on "customer" simply does nothing.
When I apply the filter, apparently the entire formula "refreshes" itself. Therefore I am currently trying to add some code to
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer).
However, being rather new to MS Access, I have no idea whether this is a step in the right direction and if so, what code I should have in Form_ApplyFilter in order to make my comboboxes clickable/updateable again.
The properties of the comboboxes are:
Row source type = Table/Query
Row source = SELECT Tbl_Liability.ID, Tbl_Liability.Liability FROM Tbl_Liability;
Bound column = 1
Enabled = Yes
Locked = No
And the form the comboboxes are in has ALLOW FILTERS set to YES (but no code in Form_ApplyFilter).

Pass parameters from one combo box to another using two forms in Microsoft Access

Just started working with Access 2016 for a project I am on.
How can I pass selected data from one form in access to another?
That Selection will be the determining factor on what data is presented in drop down menus. Basically, if I select a department, I want that departments data to be the "select from" data on the next.
I'm not really sure if this is a clear question, so I've added pictures.
The Goal is to not have to create a new form for every department.
Update:
So I am able to link the department combo box with the lineid box with the following Query
SELECT DISTINCT Line.lineName, Department.departmentName
FROM Line INNER JOIN Department ON Line.departmentID = Department.departmentID
WHERE (((Department.departmentName)=[Forms]![Production_Select_Data_Input_Destination].[OpenArgs]));
I need to get the parameter passed so this is not prompt and the combo box for lineId loads a select list of lineId's that are within the selected department.
I figured it out using
Private Sub btnEnterDataInput_Click()
DoCmd.OpenForm "frmDataInput", , , , , , OpenArgs:=cboDepartmentName
End Sub
In my first form,
and
[Forms]![frmSelectDataInput]![cboDepartmentName]
in my second form combobox row source query.
in my second form.

Access 2010 - combobox - unbound form - displaying data from an existing record

The problem I am having is displaying the correct information in a combobox on an unbound form when a users views/edits data.
The table that populates the combobox:
tblLocation
idLocation
Location
Location Description
In the tblPerson table, there is a FK field called idLocation. I have a form that allows a user to pick a person from a listbox and displays the information in textboxes and comboboxes.
The combobox is setup with these items:
idLocation <--- column width set to 0
Location
The problem I am having is having the data show up correctly in the comobox when I view/edit a new person.
When a person is selected from a ListBox, the information from tblPerson should display in textboxes and comboboxes. The textboxes work just fine. However, I'm struggling with the comboboxes. Keep in mind all of the fields
My research finds only two methods on solving this problem:
DLOOKUP
Manual check and set
If I use the DLOOKUP method:
cmbLocation = (DLookup("Location", "tblLocation", "idLocation=" & .Fields("idLocation")))
The problem is that msgBox cmbLocation will display the text and not the FK. If the user tries to edit the data, but makes no changes, it will try to save the text and not the FK.
I found a manual way that does work, but I'm not sure it is the best approach:
For i = 0 To (cmbLocation.ListCount - 1)
If Val(cmbLocation.Column(0, i)) = Val(.Fields("idLocation").Value) Then
cmbLocation = cmbLocation.ItemData(i)
Exit For
End If
Next
Again, this works - but I have to think that I'm doing something wrong - probably something obvious.
Is there a better way to do this?
you can dynamically change which data is displayed in a combobox. in your scenario, i suggest you use the OnClick event of the listbox (once the person is selected). Add the following code:
YourComboBoxName.RowSource = "SELECT * FROM tblLocation WHERE idLocation=" & FK
If after clicking on a person, the data doesn't change in the combobox, you may need a Me.Refresh
Base the form on a query that left joins in the location column.
Then that field when bound to a text box will will display automatic and without any code. And better is if the actual location value changes, then no update code etc. is required. In fact this is the whole beauty of a relational database!

How to use a query as a source for a report in MS Access 2007?

I did the following in MS Access: I made a form which had a combo box and a button. You select an option from there and click on the button and it is supposed to open a report. Now, I wrote a query selecting a few fields from a table and in the where clause, gave the condition as where name=str(combo1.value) and the report source was specified as this query. Now, when I select the value and click on the button, it opens a blank report. How can I make it load only those particular values?
I am not saving the combo box value anywhere. It said that it would remember the value for later use. Am I doing the right thing by not saving it? What should I do to make this work? Please help me!
Edit: The combo box is using values from a column 1 in a table X. I've not bound the value to any field and am using the "Remember the value for later use" option provided. The combo box is essentially a list of hotels and the report is a list of people staying at the selected hotel. When I put the ID of the field (as defined in the X), it works. But the thing is, it should refer to the names of the hotels and not the ID, which I am supposed to enter in a popup that asks for it. What do I do?
Edit 2: The query is as follows:
SELECT Table_1.Hotel_Name, Table_2.Name_of_Delegate, Table_2.Address, Table_2.City, Table_2.Center, Table_2.Spouse_Present, Table_2.No_of_Children, Table_2.No_of_Guests, Table_2.No_of_Rooms
FROM Table_1 INNER JOIN Table_2 ON Table_1.ID=Table_2.Hotel_of_Residence
WHERE Table_1.Hotel_Name=FormName.Combo7.Text;
When I click on the button (which opens the report), it asks for the name of the hotel in a popup box. How can I avoid this? What I am doing wrong?
You can use a WhereCondition with the DoCmd.OpenReport Method as a "dynamic WHERE clause" for your report's record source. Use something like this in the click event of the command button which opens your report.
DoCmd.OpenReport "YourReport", , , "[name]=" & Me.combo1
Remove the WHERE clause you added, where name=str(combo1.value), from the report's query.
I surrounded name with square brackets because name is a reserved word. See Problem names and reserved words in Access
Edit: In a comment, you said this about the combo box:
"Row Source is SELECT [Table_Name].[ID], [Table_Name].[Name] FROM [Table_Name];. Bound Column is 1 (which I assume shows the names I wish to be displayed in the combobox.)"
When you refer to the value of a combo box, that value is the value of the "Bound Column". So in your case, the bound column is 1, which means the combo value will be [Table_Name].[ID]. However, you want to open your report based on the [Name] column of the combo. So change the bound column of the combo from 1 to 2.
To open a report using the value of your combobox, in your report query you need to do the following:
SELECT fields
FROM table
WHERE YourValue = [Form]![FormName]![ComboBox Value]
You have to specify the name of the Form, plus the value so the report query knows the value. Hope this helps.