|
-
Feb 2nd, 2008, 10:10 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] text properties read only
What this error message mean?How to solve it?My combo box style is dropdownlist
Combo1.Text = .Fields("Negeri").Value
-
Feb 2nd, 2008, 10:17 AM
#2
Frenzied Member
Re: text properties read only
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
Code:
Combo1.AddItem .Fields("Negeri").Value
Combo1.Text = .Fields("Negeri").Value
But you may have to check whether item exists before you add it up
-
Feb 2nd, 2008, 10:26 AM
#3
Frenzied Member
Re: text properties read only
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:
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
You will need a Text Box(Text1) and Combo box(Combo1) to test this.
Type something in the Text Box and press enter to work it out.

EDIT: Changed code: Trim and Len switched
Last edited by zeezee; Feb 2nd, 2008 at 10:37 AM.
-
Feb 2nd, 2008, 10:27 AM
#4
Thread Starter
Frenzied Member
Re: text properties read only
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.
-
Feb 2nd, 2008, 10:34 AM
#5
Frenzied Member
Re: text properties read only
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|