M
Mishanya
I have frmClientDetails based on tblClientDetails, where the field
cboClientName in the form is a ComboBox, based on the fldClientName in the
table. E.g. I want to be able to either look or update the details by picking
the already existing ClientName, or to add a new ClientName and all his
details.
In order to enable adding a new ClientName I try to use NotInList event of
the cboClientName in the form as follows:
Private Sub cboClientName_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
Dim i As Integer
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 Book Category...")
If i = vbYes Then
strSQL = "Insert Into tblClientDetails ([ClientName]) " & _
"values ('" & NewData & "');"
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
Well, it does not work - it does enable to add a new name, but it also adds
another record named by the ClientID automatic number wich was nominated to
the record I'd tried to add, and nominates it with the next automatic number.
So, by the end of the process I have 2 new ClientName-records in the
tblClientDetails (1 of wich is "fake") but still can not view them in the
frmClientDetails, as if there are no records.
I wonder, whether I have a basic mistake in ComboBox logic (e.g. it can not
be based on and store the new value in the same field, so I have to create an
additional tblClientName and base the fldClientName of the frmClientDetails
on it) or i just have to handle the NotInList event right?
cboClientName in the form is a ComboBox, based on the fldClientName in the
table. E.g. I want to be able to either look or update the details by picking
the already existing ClientName, or to add a new ClientName and all his
details.
In order to enable adding a new ClientName I try to use NotInList event of
the cboClientName in the form as follows:
Private Sub cboClientName_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
Dim i As Integer
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 Book Category...")
If i = vbYes Then
strSQL = "Insert Into tblClientDetails ([ClientName]) " & _
"values ('" & NewData & "');"
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
Well, it does not work - it does enable to add a new name, but it also adds
another record named by the ClientID automatic number wich was nominated to
the record I'd tried to add, and nominates it with the next automatic number.
So, by the end of the process I have 2 new ClientName-records in the
tblClientDetails (1 of wich is "fake") but still can not view them in the
frmClientDetails, as if there are no records.
I wonder, whether I have a basic mistake in ComboBox logic (e.g. it can not
be based on and store the new value in the same field, so I have to create an
additional tblClientName and base the fldClientName of the frmClientDetails
on it) or i just have to handle the NotInList event right?