How to use a combobox in ms Access to display the value of field in table and at the same time present the users with a list of options to edit? - vba

I have an unbound form where my controls (among which there are some comboxes) are filled with data in a DAO.Recordset rst (opened with a SELECT SQL statement):
me.Controls("mycontrol").Value = rst.Fields("somefield")
The combobox displays the correct value ('YES' or 'NO') stored in the table. How can I make the combobox display these two options to the user if he wants to change the value? And how to I get the value the user picked (in VBA)?

Never mind. I think I did it!
mycontrol.RowSourceType = "Value List"
mycontrol.RowSource = "YES;NO"

Related

access a specific field within a query that is part of a subform

I am trying to get an understanding of what the syntax would be to access a specific field within a query that makes up a subform within another form.
Form > SubForm/Query > Field
The field I am trying to get access to a field called Berthed that operates as a Boolean field. Either the vessel is present or it is absent.
This is what I was trying and it does not work.
Me.Boat_Move_Prior_Week.SourceObject.berthed
In this case here is the breakdown
Me = current form
Boat_Move_Prior_Week = query
Berthed = field I am trying to access through the VBA
My final goal will be to create an If statement, that upon requery of the Form, will look at the Berthed field, and if the field is checked (vessel is present) do nothing, but if the field is unchecked (vessel is not present) then remove the vessel from the query.
To reach the field (on the subform) bound to the field berthed, this is the syntax (assuming the textbox on the subform also is named berthed):
IsBerthed = Me!NameOfSubformControl.Form!berthed.Value
Here an amazing guide to know how to deal with controls in main form and subforms:
Link
Aside from my syntax issues I should have been using False for the value. Thanks to the two posters above for getting me in the right direction.
If Me.Boat_Move_Prior_Week.Form!BERTHED.value = False Then
Me.Boat_Move_Prior_Week.SourceObject = ""
End If

Select combobox intem after bounded with SQL Query in Access

I have the following pair of combobox that are used for two inserts in two different access tables from a single form.
The problem I have is that I am not able to make anything else load the form is selected both in Name_OT and in Year the first value that contains corresponding combobox.
I think the solution is with:
Combobox1.Selected (0) = True 'First value
But the combobox goes blank, no text or anything appears.
Solved with this
Cuadro_combinado79 = Cuadro_combinado79.ItemData(0)
Cuadro_combinado85 = Cuadro_combinado85.ItemData(0)

How to use the value not displayed by a dropdown when connected to access database

My program uses a database in access which consists of BreedID and BreedName. I have a dropdown box in vb.net which shows the name for the user to select, however in my code I would like to store the ID related to that name so that I can send it over to the access database using oledb. Currently this is what it looks like:
Dim BrVar As String = Breed.SelectedItem.Text
But that isn't working! Please help!
You can add hidden columns to your dropdown box, it may already exist. The first column in a dropdown box is column(0) and you can set the width to 0cm. This can be for the ID value. Leaving column(1) for the Name value.
Then you can use Breed.SelectedItem.column(0)
The first thing to do is on the Data tab set up your rowsource to SELECT both the BreedID and BreedName fields (in that order). Then make sure bound column is set to 1.
Then on the Format tab set Column Count to 2 and Column Widths to 0;1.
That will have the result of displaying the BreedName field but using the BreedID field as the value of the combo box.
Use Dim BrVar As Long = Breed.SelectedItem to get the value of BreedID.

sql show listbox values only when combobox is populated

Firstly, I'm pretty new to access so I apologise if this is basic but I can't find the right answer either.
I've had some help setting this up so there are parts that have been created that I don't fully comprehend.
I have created a form that is to be used for data entry which consists of the following fields:
TEAMS - Combobox the rowsource of which is a table TEAMS; CALLREASONS - Multi-Select Listbox the records of which currently exist in a table CALLREASONS; ACTIONS - Multi-Select Listbox the records of which currently exist in a table CALLACTIONS; SUBMIT - Button with VBA which sends selected data to a number of tables.
The database works fine and things a saving where they should be and in the format they should be, the problem I'm having is with the display of the form.
I would like for the form to display blank when opened and after each time a record is submitted. However, if I set the rowsource of the listboxes to the tables all options show when the form is loaded and after each submission the options and the previous selections show.
How can I make it so that the first listbox CALLREASONS only displays possible options once a selection has been made in the combobox TEAMS and the second listbox CALLACTIONS only displays possible options once at least one selection is made in the listbox CALLREASONS ?
Thanks in advance for any help.
You can either change the controls row sources on the Update or Enter events, or you can simply enable/disable them on the events.
Lets use 3 nested comboboxes for an example.
Combo1 Has rowsource set permanently as it is the top level.
Combo2 and Combo3 Have no rowsource set.
On the Enter event of Combo2, you can set the rowsource to
SELECT Pkey, DisplayText FROM tblOptions WHERE OptionGroupField = " & Forms!Form1!Combo1BoundField
On the Enter event of Combo3, you can set the rowsource to
SELECT Pkey, DisplayText FROM tblOptions WHERE OptionGroupField = " & Forms!Form1!Combo2BoundField
So on so forth.

Access Textboxes Adding Values

I have an access database, with a form, that contains numerous textboxes. The textboxes are filled with currency data based on a selection made by the user. Each record may have different values some may have no values. I need to add 3 of the txtboxes together but the value always shows as Null.
me.txt1 = Nz(me.txt2.value + me.txt3.value + me.txt3.value)
txt2 = 23.04
txt3 = Null(empty)
txt4 = 15.64
The value of txt1 should be 38.68 instead its coming out Null. The textboxes are populated by a subroutine that is called from the AfterUpdate event of a dropdown.
Where do you use that formula ? Is it in VBA ? You don't need it.
If it's from the Control Source of txt1, then Meshould be replaced by Form (or by nothing at all)
In the Control Source property of txt1, type = nz(txt2)+nz(txt3)+nz(txt4)
That should be all you need. No VBA.
Another solution, IF the source of the form is a Query, is to add a calculated field in the query.
In both cases, of course you will NOT store that data (which would violate 3rd Normal form)