help on combo box...

  • Thread starter Thread starter ai_enjoi via AccessMonster.com
  • Start date Start date
A

ai_enjoi via AccessMonster.com

i have a combo box cbPayee... on top of the list is "add new payee..." below
which are the other names ...how can i enable it that when the 1st row is
selected, a pop-up form wud appear for data entry...

thanks...
 
Use the After Update event of the combo.

If Me.cbPayee = "add new payee..." Then
'Do it here
Else

However, a more common technique is to use the combo's NotInList event for
this purpose.
Set the combo's Limit To List property to Yes.
Delete the "add new payee..." selection
Now when the user enters a new payee that is not in the combo's row source,
the NotInList Event will fire. The NewData argument of the event will
contain what the user typed in. You can use that value to create a new
record.

Here is an example from one of my apps:

Private Sub cboMActivity_NotInList(NewData As String, Response As Integer)
'Show Error if an invalid Master Activity is entered
If MsgBox(Me.cboMActivity.Text & " Does not Exist " & vbNewLine _
& "Do you want to add it", _
vbInformation + vbYesNo, "Not Found") = vbYes Then
CurrentDb.Execute ("INSERT INTO tblMasterActivity (mactivity) " _
& "VALUES ('" & NewData & "');"), dbFailOnError
Response = acDataErrAdded
Else
Me.cboMActivity.Undo
Response = acDataErrContinue
End If
End Sub
 
Back
Top