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
Solved

Error: Object variable with block variable is not set

Posted on 2007-04-05
2
210 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

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

Suggested Solutions

Title # Comments Views Activity
Excel - Save a copy of work book 13 89
Prevent user closing word document opened with VB6 6 78
Added a column screws up code 5 63
Send outlook email from VBS Script 2 42
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

856 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