Help me to solve error '2115' in this case!

T

Tu

I make a list box in a form and write this code for this form:
' Code in module
Public noi As DAO.Database
Public Sub Ketnoi()
Set noi = CurrentDb()
End Sub

' Code in form
Dim rs1 As DAO.Recordset
Private Sub Form_Load()
Ketnoi
Set rs1 = noi.OpenRecordset(" select * from LOAISACH1 order by MaLoai asc ")
Set LstMang.Recordset = rs1
LstMang.Requery
End Sub

Private Sub LstMang_Click()
txtMaloai.SetFocus
txtMaloai.Text = rs1.Fields(0)
txtTenloai.SetFocus
txtTenloai.Text = rs1.Fields(1)
End Sub

LstMang is the list box, txtMaloai and txtTenloai are text boxs.
When i click on the list box to print the data on textbox, the programe
shows error: Run-time error '2115' The marcro or function set to the
BeforeUpdate or Validation Rule property for this field is preventing
Microsoft Office Access saving data in the field.

Please help me to solve this error. Thanks!
 
P

Paolo

Hi Tu,
I dunno the meaning of using a recordset. To populate your text boxes with
the content of the row you click on the listbox(I think is what you're trying
to do) simply do that

Private Sub LstMang_Click()

txtMaloai = LstMang.column(0)
txtTenloai = LstMang.column(1)

end sub
All this works if in LstMang.column(0) you have the value for txtMaloai and
in LstMang.column(1) you have the value for txtTenloai.

HTH Paolo
 
J

Jim Burke in Novi

There is no reason for you to define a recordset for your listbox. I would
change the listbox so that the RowSource is set to the Select statement. No
need to set the recordset property or do the requery. As long as you have the
RowSource property set the listbox will be populated when the form opens.
Then when you click on your list, set the textboxes to the appopriate values.
It sounds like you have multiple columns in your listbox, so to set the
textbox values it would be something like

txtMaloai = LstMang.column(0,lstmang.ItemsSelected(0))
txtTenloai = LstMang.column(1,lstmang.ItemsSelected(0))

This assumes the values you want for the textboxes are in the first two
columns. I don't use the .Text property when setting textbox values - it
forces you to use the SetFocus, whereas leaving it off doesn't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top