On my form I have a combo box named "cboChargeCode"
I have a table named "tblChargeCode"
I would like it so when you enter a value into the cbohargeCOde that is not listed it will alert you and ask you if you would like to add such item.
My code
Expand|Select|Wrap|Line Numbers
- Private Sub ChargeCode_NotInList(NewData As String, Response As Integer)
- Dim strSQL As String
- Dim i As interger
- Dim MSg As String
- 'Exit this sub if the combo box is cleared
- If NewData = "" Then Exit Sub
- MSg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
- MSg = MSg & "Do you want to add it?"
- i = MSgBox(MSg, vbQuestion + vbYesNo, "Unknown Charge Code...")
- If i = vbYes Then
- strsql = "Insert into tblChargeCode ([strChargeCode])" & CurrentDb.excute strSQL, dbFailOnError
- Response = acDataErrAdded
- Else
- Response = acDataErrContinue
- End If
Expand|Select|Wrap|Line Numbers
- strsql = "Insert into tblChargeCode ([strChargeCode])" & CurrentDb.excute strSQL, dbFailOnError
not sure what is going on or why it doesnt work, any help would be awesome!
Thanks