Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 17th, 2005, 10:09 AM
Registered User
 
Join Date: May 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 3219 Error: Operation Not Allowed in this Context

I have a very simple VB Application I am trying to create. I have gotten it to work in terms of queries in SQL Server but I am having trouble moving it into Visual Basic. I need to resolve this in the next day or two. Any help is greatly appreciated. I am more of a database person than a front-end person.

It keeps blowing up at this line:

    varData = rstCountErrors.GetRows(iNumRows)


This is my entire code:

Private Sub dgdCount_Click()

End Sub
Private Sub cmdGetErrorRecordDetail_Click()

    Dim rstCountErrors As Object
    Dim cnn As String
    Dim strSQL As String
    Dim fldCount As Integer
    Dim intIRow As Integer
    Dim intICol As Integer
    Dim varData As Variant

    'Create recordset and populate
    Set rstCountErrors = CreateObject("ADODB.Recordset")
    cnn = "Provider=SQLOLEDB.1;Password=just4now;Persist Security Info=True;User ID=tempsa;Initial Catalog=cmd_test;Data Source=ROSSQL20"
    strSQL = "SELECT * FROM rpt_cmd_user_count_detail WHERE date_of_report = '" & txtInputDate.Text & "' ORDER by date_of_report, update_uid"
    rstCountErrors.Open strSQL, cnn, 3 'adOpenStatic = 3

    'Clear any existing values from the spreadsheet control.
    SpdRecordDetail.ActiveSheet.Cells(1, 1).Select
    SpdRecordDetail.ActiveSheet.UsedRange.Clear

    'Add the field names as column headers.
    For fldCount = 0 To rstCountErrors.Fields.Count - 1
        intIRow = intIRow + 1
        SpdRecordDetail.ActiveSheet.Cells(1, intIRow).Value = rstCountErrors.Fields(fldCount).Name
    Next

    'Fill the control with data from the database.
    Dim iNumCols As Integer
    Dim iNumRows As Integer

    'If RS.State = adStateOpen Then RS.Close
    'RS.Source = "SELECT * FROM rpt_cmd_user_count_detail WHERE date_of_report = '" & txtInputDate.Text & "' ORDER by date_of_report, update_uid"
    'RS.Open

    iNumCols = rstCountErrors.Fields.Count
    iNumRows = rstCountErrors.RecordCount
    varData = rstCountErrors.GetRows(iNumRows)

    For intIRow = 1 To iNumRows
        For intICol = 1 To iNumCols
            SpdRecordDetail.ActiveSheet.Cells(intIRow + 1, intICol).Value = varData(intICol - 1, intIRow - 1)
        Next
    Next

    'Format the headers in row 1 with a Bold Font that is 10 points.
    With SpdRecordDetail.ActiveSheet.Range(SpdRecordDetail. Cells(1, 1), SpdRecordDetail.ActiveSheet.Cells(1, iNumCols)).Font
        .Bold = True
        .Size = 10
    End With

    'AutoFit the columns and make all text left-aligned.
    With SpdRecordDetail.ActiveSheet.Range(SpdRecordDetail. Cells(1, 1), SpdRecordDetail.ActiveSheet.Cells(iNumRows + 1, iNumCols))
        .AutoFitColumns
        .HAlignment = ssHAlignCenter
    End With

End Sub








Similar Threads
Thread Thread Starter Forum Replies Last Post
Operation is not allowed when obejct is closed zazo XSLT 19 July 25th, 2008 01:26 PM
operation is not allowed when the object is opened naveed77 Beginning VB 6 4 August 2nd, 2006 09:09 PM
Operation not allowed in context+@@Identitty jfergy Classic ASP Databases 0 March 20th, 2006 08:42 PM
Operation is not allowed when the object is closed kah Javascript How-To 2 February 16th, 2005 07:20 AM
operation is not allowed when object is closed shoakat Classic ASP Databases 1 November 26th, 2004 12:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.