Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Support Event for DBCombo Box

Status
Not open for further replies.

EddyLLC

Technical User
Mar 15, 2005
304
0
0
US
I'm using a DBCombo box populated with data from an Access2003 table. When I select a record in the combo box I want to check a second table, if a matching record is not there add it.

Does the DBCombo support an AfterUpdate event? The following code doesn't even fire when I chose a record in the combo box.

Private Sub DBcboCompany_AfterUpdate()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset

conn.Open strConn
rs.Open "Select NameofCompany,RefID From tblToDo Order By NameofCompany;", conn, dbOpenTable, dbForwardOnly
If rs.BOF And rs.EOF Then
conn.Execute "insert into tblToDo(NameofCompany) values("" & DBcboCompany.Text & "")"
End If
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
End Sub

Thanks
 
No ... but it does have a Click event that fires whenever you click on an item in the drop-down list.
Code:
Private Sub DataCombo1_Click(Area As Integer)
    [COLOR=black cyan]' Process only when the click was in the drop-down list.[/color]
    If Area = dbcAreaList Then
        Set conn = New ADODB.Connection
        Set rs = New ADODB.Recordset

        conn.Open strConn
        rs.Open "Select NameofCompany, RefID From tblToDo Order By NameofCompany;", _
                conn, dbOpenTable, dbForwardOnly
                
        If rs.BOF And rs.EOF Then
            conn.Execute "INSERT INTO tblToDo(NameofCompany) " & _
                          "VALUES('" & DBcboCompany.Text & "')"
        End If

        rs.Close
        Set rs = Nothing
        conn.Close
        Set conn = Nothing
    End If
End Sub

You do need to look at your SQL for the recordset. It is not looking for "DBcboCompany.Text" but rather for all companies in the table. rs.EOF and rs.BOF will be TRUE only if the table is completely empty.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top