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

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...
 
G

Guest

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
 
G

Guest

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
 
G

Guest

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
 

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