DataCombo Problem

woody999
10-30-2004, 10:29 AM
Hi

I am trying to use a DataCombo t0 display a field from a table. Ia m using this code:

Private Sub DataCombo1_Click(Area As Integer)
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=C:\Winsys\Visual Basic\My Programs\VB6 Sailing Boat Project\Boat Race.mdb;"

Set rs = New Recordset
rs.Open "select classname from classes", db, adOpenStatic, adLockOptimistic

With DataCombo1
Set .RowSource = rs
.ListField = "classname"
.BoundColumn = "classname"
End With

End Sub

It displays the fields but when I try to add a new record I get this message:

"The field ClassID cannot contain a null value". I'm guessing it's because it's not bound to the classID field. How can I do this?

Dennis DVR
10-30-2004, 01:37 PM
Hi woody999

a few comments in your code:

you should explicitly include the based class where your connection and recordset object belong. i.e.

Dim db As ADODB.Connection
Set db = New ADODB.Connection


and since you're initializing the rs inside the click event, you should make the rs local to the click event sub, like you did with db.

I don't see the code for adding of record.

MKoslof
10-30-2004, 02:04 PM
If you open the database table, what is the defined data type and properties of this ClassID field? Is this your primary key? Does this field allow null values? That would be the first place to start...you need to follow the rules you have set for your table constraints.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum