CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Oct 2013
    Posts
    1

    Unhappy Run-time error '91': Object variable or With block variable not set

    I'm making a sales & inventory system & i have this error... when I tried to add Listview codes(different) even though there are already different codes of adodc DataGrid View in other forms and modules...
    the problem also was I combined the declarations in the Module. Is that possible to declare two modules, one for adodc, and one for listview...??
    I have been reading several treads on this forum abut this error but i cannot solve it.

    I get an error on this line in Sub LoadData() part::: rs.Open "Select * from PurchaseOrder", db, 3, 3

    NewPurchaseOrder Form
    Code:
    Dim y
    Dim list As ListItem
    
    
    Private Sub cmdAdd_Click()
    ConnectDB
        rs.Open "Table1", db, 3, 3
            rs.AddNew
                rs(1) = txtPONumber
                rs(2) = txtDatePurchased
                rs(3) = txtSupplierName
                rs(4) = txtQuantity
                rs(5) = txtItemName
                rs(6) = txtUnitPrice
                rs(7) = txtPayableAmount
                'rs(8) = txtContact
            rs.Update
        Set rs = Nothing
        db.Close: Set db = Nothing
          LoadData
    End Sub
    
    
    Private Sub cmdDelete_Click()
    ConnectDB
                rs.Open "Select * from PurchaseOrder where ID = " & ListView1.SelectedItem, db, 3, 3
                    rs.Delete
                   
                Set rs = Nothing
            db.Close: Set db = Nothing
            LoadData
    End Sub
    
    
    Private Sub Form_Load()
    With ListView1.ColumnHeaders
            
            .Add , , "ID", 1700
            .Add , , "PO Number", 1700
            .Add , , "Date Purchased", 1500
            .Add , , "Supplier Name", 1500
            .Add , , "Quantity", 1500
            .Add , , "Item Name", 700
            .Add , , "Unit Price", 1700
            .Add , , "Payable Amount", 1000
            '.Add , , "Contact No", 1500
            
           
    
        End With
         LoadData
    End Sub
    
    Sub LoadData()
    ListView1.ListItems.Clear
    Dim list As ListItem
    Dim x As Integer
      ConnectDB
            rs.Open "Select * from PurchaseOrder", db, 3, 3
                Do Until rs.EOF
                    Set list = ListView1.ListItems.Add(, , rs(0))
                        For x = 1 To 7
                            list.SubItems(x) = rs(x)
                    Next x
                rs.MoveNext
           Loop
    
                Set rs = Nothing
            db.Close: Set db = Nothing
        
        
      ' .Add , , "Price", 800
      
    End Sub
    
    Private Sub ListView1_Click()
    txtPONumber = ListView1.SelectedItem.SubItems(1)
    txtDatePurchased = ListView1.SelectedItem.SubItems(2)
    txtSupplierName = ListView1.SelectedItem.SubItems(3)
    txtQuantity = ListView1.SelectedItem.SubItems(4)
    txtItemName = ListView1.SelectedItem.SubItems(5)
    txtUnitPrice = ListView1.SelectedItem.SubItems(6)
    txtPayableAmount = ListView1.SelectedItem.SubItems(7)
    'txtContact = ListView1.SelectedItem.SubItems(8)
    
    
    cmdAdd.Enabled = False
    cmdDelete.Enabled = True
    End Sub

    Module1 Form
    Code:
    Global rs As ADODB.Recordset
    Global conn As ADODB.Connection
    Public Sub connect()
    Dim ctr As Integer
    Dim sql As String
    
    
    
    Set rs = New ADODB.Recordset
    Set conn = New ADODB.Connection
    conn.Open "provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & App.path & "\DB.Quadcom.mdb;"
    
    End Sub

    Module2 Form
    Code:
    Public db As New ADODB.Connection
    
    Public path As String
    Public PathName As String
    Public list As String
    
    Public Sub ConnectDB()
    
        path = App.path & "\DB.Quadcom.mdb"
        
            db.Open "provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & App.path & "\DB.Quadcom.mdb;"
    
            
    End Sub
    Last edited by DataMiser; October 3rd, 2013 at 02:04 AM. Reason: added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured