Newbie question about combobox/adding row to lookup table

G

Guest

I have a bound combobox to a lookup table in Access. If an item is entered
that's not currently in the combo list, I want to add it to the list and
subsequently to the table. I've done a lot of looking thru various forums
and found the following code that does add the item to the list but I get an
exception error when trying to add it to the lookup table:

myDataView = New
DataView(Me.PhotosAndImagesDataSet.tlkpPhotographerOrIllustrator)
Me.TlkpPhotographerOrIllustratorBindingSource.DataSource =
myDataView

.....
Dim newName As String = Me.cboPhotographerOrIllustrator.Text
Dim newRow As DataRowView = myDataView.AddNew()
newRow("PhotographerOrIllustrator") = newName
newRow.EndEdit()
Me.cboPhotographerOrIllustrator.SelectedIndex =
myDataView.Count - 1

The error I get says that there must be a related record in the lookup
table. So even though the new item appears in the list, it does not get
written to the lookup table as expected.

Can anyone tell what I'm doing wrong? Thanks for any help or advice.
 
G

Guest

not at a place where I can try this, but my guess is that you need to add the
row to the datatable, not the datatableview (or maybe to both, but the table
s/b first). Just a guess.
 
G

Guest

Yes, that's what was missing. I don't need the dataview at all in this case.

Thanks very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top