Using Access 2007. I have an unbound form with 3 objects, 1 combo box and two text boxes.
The combo box uses a query as its row source. It grabs three columns from the query (Item, Lot#, and DateChanged). It has an “After Update” procedure that populates the two text boxes with the Lot# and DateChanged.
Private Sub cboItem_AfterUpdate()
Me.txtCurLot.Value = Me.cboItem.Column(1)
Me.txtDOLC.Value = Me.cboItem.Column(2)
End Sub
This all works fine if the item exists in the list. If the user starts typing in an item that doesn’t exist, I would like them to be able to type the “new item” in the combo box and then have the date text box default to current date and convert the “new item” to all upper case automatically after the new item is keyed in. I have tried the following code in the “On Not in List” event for the combo box but it doesn’t work (no errors, just doesn’t do anything)…
Private Sub cboItem_NotInList(NewData As String, Response As Integer)
Response = MsgBox("This item does not exist. Do you want to continue to add it?", vbYesNo, "NewItem")
If Response = vbYes Then
Me.txtDOLC.Value = Now()
Me.cboItem.Value = UCase$(NewData)
'Response = acDataErrAdded
End If
End Sub
There is an “Add Record” button on the form that will take care of writing the new record to the SQL table from the “On Click” event. I just want to be able to manipulate the combo and text boxes if the item doesn't already exist.
The combo box uses a query as its row source. It grabs three columns from the query (Item, Lot#, and DateChanged). It has an “After Update” procedure that populates the two text boxes with the Lot# and DateChanged.
Private Sub cboItem_AfterUpdate()
Me.txtCurLot.Value = Me.cboItem.Column(1)
Me.txtDOLC.Value = Me.cboItem.Column(2)
End Sub
This all works fine if the item exists in the list. If the user starts typing in an item that doesn’t exist, I would like them to be able to type the “new item” in the combo box and then have the date text box default to current date and convert the “new item” to all upper case automatically after the new item is keyed in. I have tried the following code in the “On Not in List” event for the combo box but it doesn’t work (no errors, just doesn’t do anything)…
Private Sub cboItem_NotInList(NewData As String, Response As Integer)
Response = MsgBox("This item does not exist. Do you want to continue to add it?", vbYesNo, "NewItem")
If Response = vbYes Then
Me.txtDOLC.Value = Now()
Me.cboItem.Value = UCase$(NewData)
'Response = acDataErrAdded
End If
End Sub
There is an “Add Record” button on the form that will take care of writing the new record to the SQL table from the “On Click” event. I just want to be able to manipulate the combo and text boxes if the item doesn't already exist.