can input msg box inputs data into table?

J

Jon

Hi,
I have a form for adding new data into a table. In this form, there is a
combo box for names, and takes it’s contains from a table called names. What
I want to do is when the user can not find the name in the combo box, I want
him to click on button and input msgbox appears and asks him to input new
name to the table. After clicking Ok, the name appears automatically in the
comb box. Who can I do that?
Note: most users do not know that they can add a data through the combo box.
 
J

Jeanette Cunningham

Hi Jon,
A combo box has an event On Not In List.
Use this event to let a user add a new record to the combo box.

Jeanette Cunningham
 
J

Jon

thank you Jenaette, you may not read my note down
"Note: most users do not know that they can add a data through the combo
box."
if you have any idea, please advice?
 
A

Arvin Meyer [MVP]

Again, use the NotInList event.

If the name is not in the list, you open your message box, something like:

Set the LimitToList property to Yes and use the OnNotinList event to do
something like this:

Private Sub cboMyCombo_Notinlist(Newdata As String, Response As Integer)
Dim db as DAO.Database
Dim rst As DAO.Recordset
Dim strMsg As String

strMsg = "Item Not Found!! Do you want to add it?"

If MsgBox(strMsg, vbQuestion + vbYesNo) = vbYes Then
Set Db = CurrentDb
Set rst = Db.OpenRecordset("underlyingTable", dbOpenDynaset)
With rst
.AddNew
![id] = me!cboMyCombo
![someOtherField] = me!cboMyCombo.Columns(1)
.Update
End With
Response = acDataErrAdded
End If

End Sub
 

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