What this error message mean?How to solve it?My combo box style is dropdownlist
Combo1.Text = .Fields("Negeri").Value
Printable View
What this error message mean?How to solve it?My combo box style is dropdownlist
Combo1.Text = .Fields("Negeri").Value
When comnbo is drop down list, it acts much like a list box. One way to around this to make sure the value you are assigning is already in the list.
try something like this
But you may have to check whether item exists before you add it upCode:Combo1.AddItem .Fields("Negeri").Value
Combo1.Text = .Fields("Negeri").Value
:wave:
This is another approach. You capture the error and add it before setting text to the combo. But this way, you wont have duplicates in the combo box. If the text is there in the combo, the text will be set to it. Otherwise, its addded to the list and then Text is set.
eg:
You will need a Text Box(Text1) and Combo box(Combo1) to test this.Code:Option Explicit
Private Sub Form_Load()
Combo1.AddItem "Test1"
Combo1.AddItem "Test2"
Combo1.AddItem "Test3"
Combo1.AddItem "Test4"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
On Error GoTo Text1_KeyPress_Error
If KeyAscii = vbKeyReturn Then
Combo1.Text = Text1.Text
End If
Exit Sub
Text1_KeyPress_Error:
If Err.Number = 383 Then
If Len(Trim(Text1.Text)) > 0 Then
Combo1.AddItem Text1.Text
Combo1.Text = Text1.Text
End If
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") "
End If
End Sub
Type something in the Text Box and press enter to work it out.
:wave:
EDIT: Changed code: Trim and Len switched
Actually I want to update the record.
The current record doen't have this value. So When I push edit button, I want to update the record by choose the value in the dropdownlist and insert this new value.
Where do you want to update the record ? In DB or combo box?
Anyway, the solution is for the error you have mentioned here. Try to change the code in Post #3 to suit your need. the Error handler part specially.
:confused: