# Access 207 - Populate textbox from combobox selection



## romeh (Mar 9, 2011)

Hi,

I have an access 2007 database; one table is called Customer Budgets, with a Customer Field and a Budget Field. 
Then i have another Table called Totals, with many fields. In the Totals Table, under the Customer Field, I have a drop-down list linked to the Customer Budgets table. I also have a Budget field in the Totals Table. When i select a customer in the Totals Table, i want the budget field to automatically populate with the corrosponding budget amount from that customer, without creating a form first. In Datasheet view:
Table: Customer Budgets
Field: Customer
Field: Budget

Table: Totals
Field: Customer - Drop-down
Field: Budget - I want to automatically populate with the budget amount from the selection made from the drop-down list.

There are many fields in my Totals table, it is just these two i struggle with.

In VB, its very simple, create a combobox and work with its "selectedindex", but for the life of me i cannot find the "equivelant" to "SelectedIndex" in access.
Pls help?

Rome'


----------



## OBP (Mar 8, 2005)

I am sorry that you have had o wait so long for an answer, as I spend my time answering on the Business Applications forum.
Before answering your question I would like point out that it is poor database design to duplicate data, so I hope you are only displaying the data on the form.
You use the Combo.column to identify the data, the first field starts at 0, so the second column is Combo.column(1)


----------



## romeh (Mar 9, 2011)

Hi OBP,

Many thanks for your response. I have taken a different approach completely, for the life of me i cannot remember now, but i was able to sort it out. Yes my database was quite messy, and i have revamped it accordingly. Many thanks for the info. I am displaying the info on the form, which is also linked to a VB project. It has been a learning experience, and what i have learned is that if your database is a mess, the rest is bound to be a mess too!

Kind regards
rome'


----------



## romeh (Mar 9, 2011)

Hi there, me again.

I have a new problem. I am HOPING you can assist. I have a database, which i have attached to a vb program. When i add data to my record, (row), it all gets saved back to the db, all except for the selections i have made from the comboboxes. very frustrating. Since i have not been able to do something like:

I want to do something like this:

RepCombobox.text = RepCombobox.SelectedItem

Something like that, but off course that doesnt work. Any idea how i can do this? Is it perhaps becuase i have made those comboboxes to select from the "reps" table in access, and then also did so in vb? no? completely lost here....

Kind regards
Rome'


----------



## OBP (Mar 8, 2005)

Well, I am not sure if you are working in Access or VB when doing this.
Normally a Combo box would be "Bound" to the field that you want to store the data in, ie. the field is the Control Source of the combo. The combo selection then gets saved automatically in to that field.
If you are working in VB (not sure why you would as Access has VBA) I do not know the syntax that you need, in Access VBA it would be 
me.RepCombobox = me.RepCombobox, which makes no sense because they both have the same name.


----------



## romeh (Mar 9, 2011)

Hi there

I have an access database, and vb6. when i select a item in the combobox, it does not appear as what i selected back in the database, everything else appears, but not the combox's selections. Make sense at all?


----------



## OBP (Mar 8, 2005)

What does appear?


----------



## romeh (Mar 9, 2011)

Nothing.... its empty.


----------



## OBP (Mar 8, 2005)

How is the combo connected to the the field in the table?


----------



## romeh (Mar 9, 2011)

Hi there, phew, i was able to sort that one out; i didnt add the control from the dataset properly, but that is sorted now.

Antoher issue (funny how, as soon as you solve one problem, the next comes RIGHT up), is that I have one dataset, i have split the fields into various forms, when i press "next", i obviously want to continue with THAT record: So I have:

Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
Dim Display As New DTP
Display.Show()
Me.Validate()
Me.Costing_MasterBindingSource.EndEdit()
Me.Costing_MasterTableAdapter.Update(Me.DatabaseDataSet)
Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet)
Me.DatabaseDataSet.AcceptChanges()
DatabaseDataSet.GetChanges()
Me.Hide()
End Sub
 
and then it opens my DTP form.

then i continue to enter the data, that is still "connected" to the dataset (db), and when i press "Next" or "save", i would expect that i would still be in the same record.

Like so:
Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
Dim Display As New Platemaking
Display.Show()
Me.Validate()
Me.Costing_MasterBindingSource.EndEdit()
Me.Costing_MasterTableAdapter.Update(Me.DatabaseDataSet)
Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet)
Me.DatabaseDataSet.AcceptChanges()
DatabaseDataSet.GetChanges()
Me.Hide()

End Sub


But when i go and check on my Database, only the items in the first form saved (InfoForm). Precicely up to the point where i opened my DTP form. Does this make sense to you at all?


----------



## romeh (Mar 9, 2011)

So it saved up to where i pressed "next" on the fist form, and nothing further... perhaps i should indicate somehow, in the Form_Load event for DTP to continue wiht the same record as the previous form? How on EARTH would one do that? You know? I think blonde must be disease... tie hie


----------



## romeh (Mar 9, 2011)

vb express & access 2007 .... just in case you ask...


----------



## romeh (Mar 9, 2011)

is my coding very amature? I have no idea whether it is up to scratch...


----------



## OBP (Mar 8, 2005)

Sorry I can't comment on your VB code as I do not know or use it. I specialise in Access design and VBA (and I used to use the old BASIC language.)
So I can only advise you on what would be done in Access, to open a second form using the same dataset Record you would refer to the Table's Key field for that record., which must be present in your second form's dataset.
So does your table have a Key field?


----------

