Solved

Error: Object variable with block variable is not set

Posted on 2007-04-05
2
201 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

772 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

14 Experts available now in Live!

Get 1:1 Help Now