Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Error: Object variable with block variable is not set

Posted on 2007-04-05
Medium Priority
Last Modified: 2010-04-30
Hi: Can any one please tell me how to i fixed that error:
Object variable with block variable is not set
on line:
    If Not IsNull(rs!clt_ref_no) Then xlWS.Cells(lngRow, 1) = rs!clt_ref_no

Private Sub DemoGraphicQueryProcess()
Dim rs
Dim strPath As String
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet
Dim lngRow As Long
Dim lngCount As Long

On Error GoTo DemoGraphicQueryProcess_Error
'This is Adaptive Server Enterprise Connection
Set DBConn = CreateObject("ADODB.Connection")
DBConn.Open "ODBC; Driver=Adaptive Server Anywhere 6.0; DSN=Debtmaster; uid=dm; pwd=,,PeAches..;"
Dim sSQL As String
sSQL = "select clt_ref_no,cur_addr1,cur_addr2,cur_city,cur_state, cur_zip, home_phone, work_phone, " & _
"cur_bal, status_abbrev,debt_descr " & _
"from dbtr_view r join debt on debt_id=debtor_id " & _
Set rs = DBConn.Execute(sSQL)
Set xlApp = New Excel.Application
Set xlWB = CreateWorkbook(xlApp)

Do While Not rs.EOF
    TotCnt = TotCnt + 1
    Debug.Print TotCnt
ProgressBar1.Max = TotCnt
ProgressBar1.Value = 1
lngRow = 2
Do While Not rs.EOF
    If ProgressBar1.Value < ProgressBar1.Max Then
        ProgressBar1.Value = ProgressBar1.Value + 1
    End If
    lngCount = lngCount + 1
    If lngCount > 50000 Then
        strPath = xlWB.Path & "\" & xlWB.Name
        xlWB.Close SaveChanges:=True
        ShellExecute 0, vbNullString, Chr(34) & strPath & Chr(34), vbNullString, vbNullString, vbMaximizedFocus
        Set xlWB = CreateWorkbook(xlApp)
        Set xlWS = xlWB.Worksheets(1)
        lngRow = 2
    End If

    If Not IsNull(rs!clt_ref_no) Then xlWS.Cells(lngRow, 1) = rs!clt_ref_no
    If Not IsNull(rs!cur_addr1) Then xlWS.Cells(lngRow, 2) = rs!cur_addr1
    If Not IsNull(rs!cur_addr2) Then xlWS.Cells(lngRow, 3) = rs!cur_addr2
    If Not IsNull(rs!cur_city) Then xlWS.Cells(lngRow, 4) = rs!cur_city
    If Not IsNull(rs!cur_state) Then xlWS.Cells(lngRow, 5) = rs!cur_state
    If Not IsNull(rs!cur_zip) Then xlWS.Cells(lngRow, 6) = rs!cur_zip
    If Not IsNull(rs!home_phone) Then xlWS.Cells(lngRow, 7) = rs!home_phone
    If Not IsNull(rs!work_phone) Then xlWS.Cells(lngRow, 8) = rs!work_phone
    If Not IsNull(rs!cur_bal) Then xlWS.Cells(lngRow, 9) = rs!cur_bal
    If Not IsNull(rs!status_abbrev) Then xlWS.Cells(lngRow, 10) = rs!status_abbrev
    If Not IsNull(rs!debt_descr) Then xlWS.Cells(lngRow, 11) = rs!debt_descr
    If Not IsNull(rs!ORIGINALACCOUNT) Then xlWS.Cells(lngRow, 12) = rs!ORIGINALACCOUNT
    lngRow = lngRow + 1
Set xlWS = Nothing
Set xlWB = Nothing
Set xlApp = Nothing

    MsgBox Err.Number & ": " & Err.Description
End Sub

Private Function CreateWorkbook(xlApp As Excel.Application) As Excel.Workbook
    Dim xlWB As Excel.Workbook
    Dim strFile As String
    strFile = "\\usnymel1fs001\new claims\IDT Carmel\upload\" & _
        Format$(Now, "MM-DD-YY") & "\" & "OXFORD_RECON_" & " " & _
        Format$(Now, "YYYYMMDD.hhmmss") & ".xls"

    Set xlWB = xlApp.Workbooks.Add
    With xlWB.Worksheets(1)
        .Range("A1").Value = "CFG_ACCOUNT"
        .Range("B1").Value = "ADDRESS1"
        .Range("C1").Value = "ADDRESS2"
        .Range("D1").Value = "CITY"
        .Range("E1").Value = "STATE"
        .Range("F1").Value = "ZIP"
        .Range("G1").Value = "PHONEHOME"
        .Range("H1").Value = "PHONEWORK"
        .Range("I1").Value = "BALANCE"
        .Range("J1").Value = "STATUS"
        .Range("K1").Value = "ORIGINALACCOUNT"
        .Range("L1").Value = "RELATIONSHIPID"
    End With
    Set CreateWorkbook = xlWB
End Function
Question by:mustish1
  • 2
LVL 12

Accepted Solution

jahboite earned 2000 total points
ID: 18861496
I have two thoughts, neither of which could be correct....

If Not IsNull(rs!clt_ref_no) Then xlWS.Cells(lngRow, 1) = rs!clt_ref_no

should that be:
If Not IsNull(rs!clt_ref_no) Then xlWS.Cells(lngRow, 1).value = rs!clt_ref_no ?

Dim xlWS As Object

instead of
Dim xlWS As Excel.Worksheet
LVL 12

Expert Comment

ID: 18861535
My english it not so good. Where I write "neither of which could be correct", I actually mean that one or both could be correct....

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 1 hour left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question