PDA

View Full Version : mình hỏi một chút về listview



camellia987
02-04-2008, 09:59
Mình đang làm một bài về listview khi cick lên một dòng dữ liệu thì chi tiết của dòng dữ liệu ấy hiện chi tiết lên một form khác nhưng trong form load lại báo lỗi thế này
Private Sub Form_Load()
Dim rsAuthors As ADODB.Recordset, LItem As ListItem
Set rsAuthors = New ADODB.Recordset
Set rsAuthors = gclsAuthors.GetAuthorsList()
With rsAuthors
On Error Resume Next
Do Until .EOF
Set LItem = lvwAuthors.ListItems.ADD(, "A" & !au_id, !au_lname)
LItem.SubItems(1) = !au_fname
LItem.SubItems(2) = !address
LItem.SubItems(3) = !city
LItem.SubItems(4) = !State
LItem.SubItems(5) = !zip
LItem.SubItems(6) = !phone
LItem.SubItems(7) = !contract
.MoveNext
báo lỗi tại dòng Set rsAuthors = gclsAuthors.GetAuthorsList()
báo lỗi object variable or with block variable not set.
Mình chịu không hiểu tại sao nữa.giúp mình nhé.thnk

huytranaz
02-04-2008, 12:10
Mình đang làm một bài về listview khi cick lên một dòng dữ liệu thì chi tiết của dòng dữ liệu ấy hiện chi tiết lên một form khác nhưng trong form load lại báo lỗi thế này
Private Sub Form_Load()
Dim rsAuthors As ADODB.Recordset, LItem As ListItem
Set rsAuthors = New ADODB.Recordset
Set rsAuthors = gclsAuthors.GetAuthorsList()
With rsAuthors
On Error Resume Next
Do Until .EOF
Set LItem = lvwAuthors.ListItems.ADD(, "A" & !au_id, !au_lname)
LItem.SubItems(1) = !au_fname
LItem.SubItems(2) = !address
LItem.SubItems(3) = !city
LItem.SubItems(4) = !State
LItem.SubItems(5) = !zip
LItem.SubItems(6) = !phone
LItem.SubItems(7) = !contract
.MoveNext
báo lỗi tại dòng Set rsAuthors = gclsAuthors.GetAuthorsList()
báo lỗi object variable or with block variable not set.
Mình chịu không hiểu tại sao nữa.giúp mình nhé.thnk

Khi gặp lỗi: "Object variable or with block variable not set" có nghĩa là biến đối tượng đó chưa được khởi tạo. Như trong đoạn code của bạn, mình không thấy dòng khởi tạo đối tượng gclsAuthors.
Lưu ý thêm trong 2 dòng code của bạn:


1 Set rsAuthors = New ADODB.Recordset
2 Set rsAuthors = gclsAuthors.GetAuthorsList()

Ở dòng 1 không có ý nghĩa, vì lệnh set rsAuthors ở dòng thứ 2 sẽ khởi tạo lại đối tượng rsAuthors.
Để đoạn code của bạn chạy đúng, bạn cần sửa:
- Khởi tạo gclsAuthors.
- Phương thức: GetAuthorsList() của lớp đối tượng clsAuthors phải trả về kiểu ADODB.Recordset.

Chúc thành công,