How to get selected value of a combobox in access - vba

I have employee_ID in combo box list. On change of the e_ID I want the selected value to be show in the name and address field using VBA Access code.
How can I get this?

Related

MS Access Displayed v. Saved Value in Combo Box

I have a simple database with two tables and one relationship between them:Employees, Managers, Relationship.
Each employee has exactly one manager, but each manager can manage multiple employees. For adding employees to the database, I have this form: Employee Form.
As it stands, the user must enter the ManagerID of the new employee's manager when adding an employee. What I would like is for the user to select the new employee's manager from a combo box. The drop down options should be the names of the managers (say, from the FullName column of the Managers table). However, once the user selects a name from the drop down, I would like the ManagerID corresponding to that name to be saved in ManagerID field of new employee's entry.
Can I solve this problem by basing the form off of a query, or will I need to customize the form/combo box with some VB code?
This will take basically just one line of VBA code; most of it is done through Access.
Point the combo box's data source to the table of managers. In the 'Row Source' property of the combo box under 'Data' in the Property Sheet, set the Row Source to a query for the first + last name of the managers. For example:
SELECT ManagerID, FirstName, LastName FROM tblManagers ORDER BY FirstName;
Then go to the ComboBox's Format tab and set the Column Count to 3. Set the column widths appropriately; to hide the first column with the ID field, set it to 0, and set the other column widths to whatever looks right. For example: 0";0.5"'0.5" will hide the first column, and set the other two to a half-inch width.
To have the TextBox automatically display the ID number of the manager in the ComboBox (which honestly, if you don't need to display it for some reason, why not just hide the ID field from the user altogether? Food for thought), you will need to add the VBA code to the ComboBox's AfterUpdate event. That way, whenever the combo box is updated, the textbox will change accordingly. You may need to first go into design mode and change the 'HasModule' property of the form to 'Yes'; after that, use the 'Events' tab of the ComboBox's Property Sheet to open up the code builder for the 'After Update' event. It should take you to the VBA builder, with an auto-generated Private Sub [combobox's name]_AfterUpdate()
Set the code to the following:
Private Sub ComboBox_AfterUpdate() 'Obviously, sub your combo boxs name for ComboBox
Me.TextBox = Me.ComboBox 'Obviously, sub your text boxs name and your combo boxs name here
End Sub
Since the default bound column for the ComboBox is the first, this sets the value of the text box to the value of the first column of the ComboBox.

Getting typed OR selected value from combo box

I have a combo box (myCB) in a form. The user can either select a drop down value or type a value in the box. When the user clicks a button, I want to get the value in the combo box for use in a query.
I am using myCB.Column(0) to grab the value. This works if the user has clicked a selection in the combo box. However, if the user has typed the value, then myCB.Column(0) is null. I have also tried myCB.Text and myCB.Value. Both give null.
How can I grab the combo box value regardless of whether it was selected or typed?
Edited to add properties:
Row Source: "SELECT DISTINCT Item FROM tblItems" (this is set in VBA code, and not in property sheet)
Bound Column: 1
Column Count: 1
Column Widths:
Control Source: ItemName
Figured it out. I was grabbing the combo box value after DoCmd.GoToRecord , "", acNewRec in the OnClick procedure, and the behavior was wonky. Running the value-testing stuff before a new record is accessed yields the correct behavior. Thank you everyone for your help.

how to get textbox value from row of a gridview xaml

I bind a list of jobtype values to a gridview, each row have sno,jobtype,check box,and a text box. when a check box is checked the text box will enable, and I have to enter some value(like fee) here I can check multiple jobtypes,and enter fee in text box, and finally save these values( jobtype, fee) I successfully bind the data, but how to get that entered value from text box of each row?? And how can I enable or disable text box on checked or unchecked the check box.. Please give me solution
You cant have JobType as the DataContext for row.
You need to build a wrapper around it, that will contain JobType, and the other strings you wish your TextBoxes to Bind to.
Your list of JobTypes should be a list of that wrapper.

MS Access combo box subform filter afterupdate

I have a combo box, when I select a value, I would like the subform to filter on a particular field with that respective value.
I cannot figure out how to get the Macro Action Builder on After update to function correctly, so I am trying some vba in the afterupdate event field for the combo box.
One line of code in the event field: "SELECT * FROM [fsubtotal] WHERE [Fund Codes] = " & cbo1.Column(0)
fsubtotal is my subform and Fund Codes is the Field I want to apply the filter to. I'm not sure if I should use 0 or 1 for Column(x), as 0 is the key ID in auto number format, but 1 would be the actual fund codes in short text format.
You should be able to link the subform to the combo box in question by selecting the subform container, and then in the property sheet, going to Data -> Link Master Fields. The master field is whatever field you want to connect from the master form.

Add a field value to text box

I have an Access Table named Count. It has one field named Anz and it has only 1 record. I want to Show this record in a TextBox on a form named overview. So in the design mode of the form inside the TextBox I use the code
[Count]![Anz]
but it Returns me #Name? error when I Switch back to form mode. Where am I going wrong?
You can use in Control Source of your unbound text box =Dlookup("[Anz]","[Count]")
Also you can bound your form to Count table and use for text box control source Anz