Advertisement

01.08.2008 at 07:58AM PST, ID: 23066768
[x]
Attachment Details

runtime error 3704 application defined or object defined error

Asked by jtammyg in Microsoft Visual Basic.Net, Visual Basic Programming, Microsoft Excel Spreadsheet Software

Tags: VBA, runtime error 3704 application defined or object defined error

Hi!

I have the following code that gets start date from a cell, end date from another cell and previous date from a thrid cell. Then it runs a stored proc off SQL Server with those 3 parameters and should spit the recordset outon another worksheet.

Sub Billing_Report()
 

  'Clear previous contents
Sheet1.Range("A9:AZ5000").Select
Selection.ClearContents


Sheet1.Range("C3").Value = "(for the period of " & Sheet2.Range("E10").Value & " to " & Sheet2.Range("E20").Value & ")"


   'release the selection from the previous step
Sheet1.Range("E5").Select


 'initialize variables with data in those cells
Start_Date = Sheet2.Range("E10").Value
End_Date = Sheet2.Range("E20").Value
Prev_Date = Sheet2.Range("E30").Value



    'checking if end_date happens earlier than start_date
If End_Date < Start_Date Then
        MsgBox "Start Date must be earlier than End Date. Check your selection and try again"
        Worksheets("Selection Data").Activate
        Exit Sub
End If


    'checking if prev_date happens after than start_date
If Prev_Date > Start_Date Then
        MsgBox "Previous Date must be earlier than Start Date. Check your selection and try again"
        Worksheets("Selection Data").Activate
        Exit Sub
End If


 'Declare the variables
Dim conn As ADODB.Connection
Dim Rs As ADODB.Recordset
Dim strSQL As String, ConnStr As String


  'Set the connection string
ConnStr = "Provider=SQLOLEDB;Initial Catalog=master; Data Source=dr-ny-sql001; " & _
"INTEGRATED SECURITY=sspi;"
 
 
 'create  sql string for stored proc
strSQL = "exec usp_DR_Monthly_Billing_Report '" & Start_Date & "', '" & End_Date & "', '" & Prev_Date & "'"

'MsgBox strSQL
 
 
  'create and open the connection and recordset
Set conn = New ADODB.Connection
Set Rs = New ADODB.Recordset
conn.CommandTimeout = 0
conn.Open ConnStr
Rs.Open strSQL, conn, adOpenForwardOnly, adLockReadOnly


  'Instantiate the Recordsetobject and execute the question.
Set Rs = conn.Execute(strSQL)


'If conn.State = adStateClosed Then
        'MsgBox "connection is closed"
'Else
        'MsgBox "connection is open"
'End If


'If Rs.State = 1 Then
        'MsgBox "Recordset is closed"
'Else
        'MsgBox "Recordset is open"

'If Rs.RecordCount > 0 Then MsgBox "The report has been populated with " & Sheets("Selection Data").ComboBox1.Value & " data from " & Sheets("Selection Data").Calendar1.Value & " to " & Sheets("Selection Data").Calendar2.Value Else If Rs.RecordCount <= 0 Then MsgBox "There is no data for " & Sheets("Selection Data").ComboBox1.Value & " for the period from " & Start_Date & " to " & End_Date

'If Not Rs.EOF Then
             'MsgBox "The report has been populated with data from " & Start_Date & " to " & End_Date
       ' Else
             'MsgBox "There is no data for the period from " & Start_Date & " to " & End_Date
'End If


  'Dump the records into the worksheet.
Sheet1.Range("A9").CopyFromRecordset Rs

 
   'Release objects from memory.
If Rs.State = 1 Then Rs.Close
    Set Rs = Nothing
    conn.Close
    Set conn = Nothing

 

' Exit the macro so that the error handler is not executed.
      Worksheets("Selection Data").Activate


'WrongDate:

     'MsgBox "End Date cannot happen before Start Date. Please check your selection and try again."



'Errhandler:

      'MsgBox "Error # " & Err & " : " & Error(Err) & ". Please make a note of this error message and contact Technical Support."

' Exit the macro so that the error handler is not executed.
      'Exit Sub
 
End Sub



I am getting runtime error 3704 application defined or object defined error
when hitting the following line:

  'Dump the records into the worksheet.
Sheet1.Range("A9").CopyFromRecordset Rs


Any help will be greatly appreciated.

Thanks!

JTStart Free Trial
[+][-]01.08.2008 at 08:06AM PST, ID: 20609653

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.08.2008 at 08:14AM PST, ID: 20609753

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.08.2008 at 09:12AM PST, ID: 20610472

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.08.2008 at 09:15AM PST, ID: 20610502

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.08.2008 at 09:16AM PST, ID: 20610508

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.08.2008 at 09:19AM PST, ID: 20610540

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.08.2008 at 09:23AM PST, ID: 20610581

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.08.2008 at 09:39AM PST, ID: 20610725

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.09.2008 at 05:16AM PST, ID: 20617787

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.22.2008 at 09:53AM PST, ID: 20716372

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, Visual Basic Programming, Microsoft Excel Spreadsheet Software
Tags: VBA, runtime error 3704 application defined or object defined error
Sign Up Now!
Solution Provided By: jtammyg
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628