Hi all,
Need a little help here. This has been driving me nuts, not even sure it can work. I look to be real close with it however, so I am thinking it might.
I have a form with two combo boxes on it. i.e Type and Model, by choosing a Type, certain Models will showup. All works well until a new Model needs to be entered. Both Combo's are stored in a table called tblModelA, with only two fields Type and Model. I am using code to prompt the user if they want to add the Model to the list if it is not already there. Were I run into trouble is trying to populate the Type field, while creating the new Model into a new record. The code I am using is below. I can not figure out were I am going wrong, it keeps failing on the CurrentDB.execute line. Anyone have any ideas?
Private Sub ModelID_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
Dim i As Integer
Dim Msg As String
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 Model...")
If i = vbYes Then
strSQL = "Insert Into tblModelA ([Model],[Type]) values ('" & NewData & "') & ('" & Me.Type.Value & "')"
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
Thanks in advance,
ScorpioX
Need a little help here. This has been driving me nuts, not even sure it can work. I look to be real close with it however, so I am thinking it might.
I have a form with two combo boxes on it. i.e Type and Model, by choosing a Type, certain Models will showup. All works well until a new Model needs to be entered. Both Combo's are stored in a table called tblModelA, with only two fields Type and Model. I am using code to prompt the user if they want to add the Model to the list if it is not already there. Were I run into trouble is trying to populate the Type field, while creating the new Model into a new record. The code I am using is below. I can not figure out were I am going wrong, it keeps failing on the CurrentDB.execute line. Anyone have any ideas?
Private Sub ModelID_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
Dim i As Integer
Dim Msg As String
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 Model...")
If i = vbYes Then
strSQL = "Insert Into tblModelA ([Model],[Type]) values ('" & NewData & "') & ('" & Me.Type.Value & "')"
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
Thanks in advance,
ScorpioX