Re: Proper using of Combobox

Tech-Archive recommends: Speed Up your PC by fixing your registry



Show us the RowSource query for the combobox. And the ControlSource for the
combobox.

Also, are you saying that your combobox's NotInList code is adding two
records to the tbClientList table? I'm not fully understanding your
reference to "two records".
--

Ken Snell
<MS ACCESS MVP>


"Mishanya" <Mishanya@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:91852B04-DF56-45C9-8C21-B4D5640888D9@xxxxxxxxxxxxxxxx
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?



.



Relevant Pages

  • Re: Whats wrong with the combobox in grid
    ... There are a lot of combobox samples on Internet for VBNet. ... Private _cboColumn As ComboBox ... Public Sub New(ByVal objSource As DataSet, ByVal strMember As String, ... Dim index As Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Populating Combobox
    ... above the "Sub" routine and I was wondering how that works. ... Dim iq As itemqty ' Userform with combobox ... Chip Pearson explains why using "dim xxx as New yyyy" is a bad idea: ... combobox, I was using textboxes without incident. ...
    (microsoft.public.excel.programming)
  • Re: Populating Combobox
    ... above the "Sub" routine and I was wondering how that works. ... Dim iq As itemqty ' Userform with combobox ... Chip Pearson explains why using "dim xxx as New yyyy" is a bad idea: ... combobox, I was using textboxes without incident. ...
    (microsoft.public.excel.programming)
  • Re: Populating Combobox
    ... above the "Sub" routine and I was wondering how that works. ... Dim iq As itemqty ' Userform with combobox ... Chip Pearson explains why using "dim xxx as New yyyy" is a bad idea: ... combobox, I was using textboxes without incident. ...
    (microsoft.public.excel.programming)
  • Re: Dependent ComboBoxes as Critiria for VLOOKUP or OFFSET
    ... Private Sub ComboBox1_Change ... Dim Sh As Worksheet ... Dim CB2 As ComboBox ... The problem with that solution is the design of the secondary lists. ...
    (microsoft.public.excel.programming)