hello all, please help.
I have this combobox, which contain list of something.
what i want is once the user enters or type a value in that combobox, but which is not in the list yet.
i want it to add in the table but my code is not working i don't know why. pls help.
table:
ID (primary key)
Category (text)
code below:
Private Sub Combo0_BeforeUpdate(Cancel As Integer)
Dim cn As ADODB.Connection, RS As New ADODB.Recordset
Dim strSQL As String
Dim i As Integer
Dim blnExist As Boolean
Set cn = CurrentProject.Connection
cn.BeginTrans
RS.Open "tbl_ComboTest", cn, adOpenKeyset, adLockOptimistic
blnExist = False
RS.MoveFirst
For i = 1 To RS.RecordCount
If Me.Combo0.Text = RS![Category] Then
blnExist = True
End If
RS.MoveNext
Next i
If Not blnExist Then
RS.AddNew
RS![Category] = Combo0.Text
RS.Update
End If
RS.Close
I have this combobox, which contain list of something.
what i want is once the user enters or type a value in that combobox, but which is not in the list yet.
i want it to add in the table but my code is not working i don't know why. pls help.
table:
ID (primary key)
Category (text)
code below:
Private Sub Combo0_BeforeUpdate(Cancel As Integer)
Dim cn As ADODB.Connection, RS As New ADODB.Recordset
Dim strSQL As String
Dim i As Integer
Dim blnExist As Boolean
Set cn = CurrentProject.Connection
cn.BeginTrans
RS.Open "tbl_ComboTest", cn, adOpenKeyset, adLockOptimistic
blnExist = False
RS.MoveFirst
For i = 1 To RS.RecordCount
If Me.Combo0.Text = RS![Category] Then
blnExist = True
End If
RS.MoveNext
Next i
If Not blnExist Then
RS.AddNew
RS![Category] = Combo0.Text
RS.Update
End If
RS.Close