PC Review


Reply
Thread Tools Rate Thread

Adding Records to a Record set

 
 
=?Utf-8?B?R2VvZmYgTXVybGV5?=
Guest
Posts: n/a
 
      15th Mar 2004
I have a Windows form with a number of Bound Controls. When I want to add a new record I clear all the combo boxes and text boxes by setting the text properties to "". To add a new record to the dataset I use

Dim drNew As System.Data.DataRo
drNew = Me.DsEstablishMaint1.Establishments.NewRo
With drNe
.Item("Code") = txtEstCode.Tex
.Item("Name") = txtName.Tex
.Item("Street") = txtAddress1.Tex
e.t.c
End Wit
DsEstablishMaint1.Establishments.AddEstablishmentsRow(drNew

The problem I have got is that I have a bound Combobox at the top of my form to select a record based on name. After adding a new record the name on the record I have just entered appears twice: once in the correct alphabetical position and once at the end of the list. If I try and select any name in the list my program crashes with "Duplicate values are not allowed on name" which is my primary key. I have tried experimenting with Currency Manager's AddNew() method but this created further problems. So is there a way to prevent the duplicate values appearing in my combo box and why should this happen anyway?

 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      15th Mar 2004
Hi Geoff,

An advice never type recordset in your subject, mostly that are unanswered
questions here.

More because you use a dataset.

Try to set a dataview between it.
dv = new dataview(dsEstablishment1.establishments)
dv.sort = "Name" 'or whatever
cb.datasource = dv

Then it will me showup sorted.

Because this was your first problem I do not know if the next will stay?

Cor


> I have a Windows form with a number of Bound Controls. When I want to add

a new record I clear all the combo boxes and text boxes by setting the text
properties to "". To add a new record to the dataset I use:
>
> Dim drNew As System.Data.DataRow
> drNew = Me.DsEstablishMaint1.Establishments.NewRow
> With drNew
> .Item("Code") = txtEstCode.Text
> .Item("Name") = txtName.Text
> .Item("Street") = txtAddress1.Text
> e.t.c.
> End With
> DsEstablishMaint1.Establishments.AddEstablishmentsRow(drNew)
>
> The problem I have got is that I have a bound Combobox at the top of my

form to select a record based on name. After adding a new record the name
on the record I have just entered appears twice: once in the correct
alphabetical position and once at the end of the list. If I try and select
any name in the list my program crashes with "Duplicate values are not
allowed on name" which is my primary key. I have tried experimenting with
Currency Manager's AddNew() method but this created further problems. So is
there a way to prevent the duplicate values appearing in my combo box and
why should this happen anyway?
>



 
Reply With Quote
 
William Ryan eMVP
Guest
Posts: n/a
 
      15th Mar 2004
Geoff:

Is there anything else happening, perhaps behind SelectedItem changed or
anything like that. I used your exact code and it just adds it once at the
end. Also, do you have it sorted or anything?
"Geoff Murley" <(E-Mail Removed)> wrote in message
news:2BA7B04E-DE75-4218-A223-(E-Mail Removed)...
> I have a Windows form with a number of Bound Controls. When I want to add

a new record I clear all the combo boxes and text boxes by setting the text
properties to "". To add a new record to the dataset I use:
>
> Dim drNew As System.Data.DataRow
> drNew = Me.DsEstablishMaint1.Establishments.NewRow
> With drNew
> .Item("Code") = txtEstCode.Text
> .Item("Name") = txtName.Text
> .Item("Street") = txtAddress1.Text
> e.t.c.
> End With
> DsEstablishMaint1.Establishments.AddEstablishmentsRow(drNew)
>
> The problem I have got is that I have a bound Combobox at the top of my

form to select a record based on name. After adding a new record the name
on the record I have just entered appears twice: once in the correct
alphabetical position and once at the end of the list. If I try and select
any name in the list my program crashes with "Duplicate values are not
allowed on name" which is my primary key. I have tried experimenting with
Currency Manager's AddNew() method but this created further problems. So is
there a way to prevent the duplicate values appearing in my combo box and
why should this happen anyway?
>



 
Reply With Quote
 
=?Utf-8?B?R2VvZmYgTXVybGV5?=
Guest
Posts: n/a
 
      16th Mar 2004
Thanks for your suggestions. I think my problems were caused by having a text box and a combo box bound to the same database field. I have also added a Dataview sorted on my name field. So everyting is working as it should now

Thanks again.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Many Records to Unsaved One Record =?Utf-8?B?TXVycA==?= Microsoft Access Form Coding 3 15th Feb 2007 05:24 PM
adding records if record source is query =?Utf-8?B?U2FuZHlS?= Microsoft Access Forms 6 1st May 2006 06:15 PM
Stop 'next record' from adding from adding records Ynot Microsoft Access Form Coding 6 12th Dec 2005 01:20 AM
Adding Record/Records =?Utf-8?B?SGFyZGRyaXZlNzQ3?= Microsoft Frontpage 1 17th Nov 2004 09:09 PM
Adding Related Records to New Record =?Utf-8?B?U2hlbGRvbiBQZW5uZXI=?= Microsoft Access Form Coding 13 28th Oct 2004 04:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:15 AM.