hi all
I'm using VB6 and ms access 97 as the database.
Actually I modified these codes from a vb6 books somewhere and make it to suit my need as a learning tools.
Just wondering'¦ is there anything wrong with these lines of codes and functions.
What I'm trying to do is that I wanted to call the Select_Item function in class (Financial.dll). This will populate all the textbox in the clientFrm with the related data, base on the itemNo. And ad the same time will populate the listview (lstView) upon loading of the client form.
The Select_data function below is in a client form (clientFrm.vbp). I called it on form open and on refresh command button_click
Code:
'ClientFrm.vbp
Private Sub Select_Data()
Dim itmNew As ListItem
Set rsFinancial = New ADODB.Recordset
Set rsFinancial = objFinancial.Select_Item
lstView.ListItems.Clear
If rsFinancial.EOF And rsFinancial.BOF Then
Set rsFinancial = Nothing
Exit Sub
End If
Do Until rsFinancial.EOF
Set itmNew = lstView.ListItems.Add _
(, rsFinancial("itemNo"), rsFinancial("itemNo"))
itmNew.SubItems(1) = rsFinancial("ItemDesc")
itmNew.SubItems(2) = rsFinancial("unitPrice")
itmNew.SubItems(3) = rsFinancial("qtyStock")
itmNew.SubItems(4) = rsFinancial("Status")
rsFinancial.MoveNext
Loop
Set rsFinancial = Nothing
End Sub
'Financial.cls compiled to financial.dll
'+++++++++
Public Function Select_Item(Optional itemNo As String) As Object
Dim strSQL As String
On Error GoTo BadSelect
strSQL = "SELECT * FROM itemMaster"
If Trim(" " & itemNo) <> " " Then
strSQL = strSQL & " WHERE itemNo= '" & itemNo & "'"
End If
Set Select_Item = cnFinancial.Execute(strSQL)
Exit Function
BadSelect:
Debug.Print Err.Number & Err.Description
Select_Item = Err
Err.Clear
End Function
Is there a problem in the code somewhere? because nothing happens during my form open and during cmd refresh button click. I also noticed that my "itemNo" from the Select_Item function contains null " " when i trace it using the break mode. My table all have data and the ItemNo is the primary key.
2.
this is from the same project in the clientfrm
ListView
Code:
Private Sub lstView_Click()
On Error GoTo SelectError:
Set rsFinancial = New ADODB.Recordset
Set rsFinancial = objFinancial.Select_Item(lstView.SelectedItem.Key)
If rsFinancial.EOF And rsFinancial.BOF Then
Set rsFinancial = Nothing
Exit Sub
End If
txtItemNo = rsFinancial("itemNo")
txtItemDesc = rsFinancial("ItemDesc")
txtUPrice = rsFinancial("UnitPrice")
txtQtyStock = rsFinancial("qtyStock")
cmbStatus = rsFinancial("Status")
Set rsFinancial = Nothing
Exit Sub
SelectError:
MsgBox Err.Number & Err.Description
Err.Clear
End Sub
Whenever I clicked the listview I got this error message.
"91 Object Variable or With block variable not set"
what is that mean? Is it related to the previous problem as well?
Thank for all the help and will be much appreciated
Kuman.
P/s: if the info is not enough please let me know I really need to finish this and i'm still in the learning process :0)
thanks again
[This message was edited by kuman on May 13, 2002 at 03:41.]