Solved

Error: Object variable with block variable is not set

Posted on 2007-04-05
2
207 Views
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
Thanks.

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 " & _
",substring(DEBT_DESCR,(LOCATE(DEBT_DESCR,':',1)+1), 20) AS ORIGINALACCOUNT " & _
"from dbtr_view r join debt on debt_id=debtor_id " & _
"WHERE CLT_ID LIKE 'IDTC%' AND R.STATUS_CODE<'400';"
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
    rs.MoveNext
Loop
ProgressBar1.Max = TotCnt
ProgressBar1.Value = 1
lngRow = 2
rs.movefirst
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
    rs.MoveNext
Loop
Set xlWS = Nothing
Set xlWB = Nothing
xlApp.Quit
Set xlApp = Nothing

DemoGraphicQueryProcess_Error:
    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
0
Comment
Question by:mustish1
  • 2
2 Comments
 
LVL 12

Accepted Solution

by:
jahboite earned 500 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 ?
   


Try
Dim xlWS As Object

instead of
Dim xlWS As Excel.Worksheet
0
 
LVL 12

Expert Comment

by:jahboite
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....
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now