?
Solved

Error: Object variable with block variable is not set

Posted on 2007-04-05
2
Medium Priority
?
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 12

Accepted Solution

by:
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 ?
   


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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

764 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