Sample code to add new field to an underlying table??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone provide sample code to add a new record to a combo box where data
is added to an underlying table. Any information with regards the problems
adding a new record would be greatly appreciated...
 
Mike,
Assuming you're adding data to the table specified in the combobox's
rowsource, it's simply a matter of requerying the combobox:

Me.MyCombobox.Requery

HTH,
Barry
 
Hi Barry

Sorry, my original question wasn't worded correctly. I have a combo box
which gets its information from an underlying table. If i want to add a new
entry to the combo how can i do it using the 'notinlist' event so that it
creates a new record in the underlying table...

Regards
Mike
 
The simplest is to use the Docmd.RunSql method:


Private Sub Combo1_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
If MsgBox("Add record to database?", vbOKCancel + vbQuestion, "Confirm")
= vbOK Then
strSQL = "INSERT INTO MyTable(Field1) Values('" & Me.Combo1 & "')"
DoCmd.RunSQL strSQL
End If
Response = acDataErrContinue
Me.Combo1.Requery
End Sub

HTH,
Barry
 
Back
Top