Results 1 to 9 of 9

Thread: runtime error 3021

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    runtime error 3021

    hi,please help.when i try to plot chart from the mschart have this runtime error appear.Runtime error '3021'.

    this is the current code:
    Code:
    Con.Open "driver={SQL Server};Server=ERP_server;Uid=sa;pwd=sa;database=SPC"
    
    Set Rss = Nothing
    Rss.Open " Select sum(sampleno/5)as subgroup,avg(data)as avgdata ,avg(sevenpoint)as seven, time,date from spcdata where date between '" & Format$(startdate, "yyyy-mm-dd") & "' and '" & Format$(enddate, "yyyy-mm-dd") & "' and partno ='" & partno & "'and dimension = '" & dimension & "' and machineno ='" & machineno & "'group by date,time", Con, adOpenKeyset ' Making Recordset
    rs1.Open "SELECT PartNo, Dimension,Nominal, UCL, LCL From PartList WHERE PartNo = '" & partno & "' AND Dimension = '" & dimension & "' ", Con, adOpenKeyset ' Making Recordset
     
         If Rss.RecordCount = 0 Then ' If no Record in Database, then Show an Error Msg and Exit the Sub
        Else
            ReDim ArrayChart(1 To Rss.RecordCount, 1 To 5) ' Array
            For X = 1 To Rss.RecordCount
            ArrayChart(X, 1) = Rss!avgdata
            ArrayChart(X, 2) = rs1!ucl
            ArrayChart(X, 3) = rs1!lcl
            ArrayChart(X, 4) = (rs1!lcl + rs1!ucl) / 2
            ArrayChart(X, 5) = Rss!seven
                     Rss.MoveNext
            Next X
      
        ' 'Set manually the setting of the Scale of Axis
    MSChart1.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
    MSChart1.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = (rs1!ucl) + (0.2 * ((rs1!ucl) - (rs1!lcl)))
    MSChart1.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = (rs1!lcl) - (0.2 * ((rs1!ucl) - (rs1!lcl)))
          
            
    '# Assigns array to the MSChart control #
        MSChart1.ChartData = ArrayChart
        MSChart1.SeriesType = VtChSeriesType2dLine
        MSChart1.Refresh
        End If
        
          If Rss!seven < rs1!lcl Then error message higlight at this line
                   MSChart1.Plot.SeriesCollection(5).SeriesMarker.Show = False
            Else
                    MSChart1.Plot.SeriesCollection(5).SeriesMarker.Show = True
            End If
        
        
        With MSChart1.Plot.SeriesCollection(1)
            .SeriesMarker.Auto = False      
            .DataPoints.Item(-1).Marker.Visible = True
            .DataPoints.Item(-1).Marker.Size = 65
            .DataPoints.Item(-1).Marker.Style = VtMarkerStyleSquare
            End With
            
           With MSChart1.Plot.SeriesCollection(5)
            .SeriesMarker.Auto = False       
            .DataPoints.Item(-1).Marker.Visible = True
            .DataPoints.Item(-1).Marker.Size = 65
            .DataPoints.Item(-1).Marker.Style = VtMarkerStyleSquare
            End With
                
     Set Rss = Nothing
     Set rs1 = Nothing
            
    End Sub
    actually i'm try to hide the marker if the rss!seven is less than the rs1!lcl scale .i don't know is work for mschart from vb or not.please help thanks.
    Attached Images Attached Images  
    Last edited by gracehskuo; Jun 15th, 2008 at 09:53 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: runtime error 3021

    You should not be using the Recordcount property as depending upon the sursor location and lock type it wont be supported.

    Use the BOF and EOF comparisons to determine if there are records present in your recordset.


    Code:
    If (oRs.BOF = True) AND (oRs.EOF = True) Then
        'No records
    Else
        'records
    End If
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: runtime error 3021

    hi,thanks reply.i still facing the same error message.please guide .

    this is the current code:
    Code:
    If Not Rss.EOF And Rss.BOF Then
        MsgBox "no record"
        Else
         If Rss!seven < rs1!lcl Then
                   MSChart1.Plot.SeriesCollection(5).SeriesMarker.Show = False
            Else
                    MSChart1.Plot.SeriesCollection(5).SeriesMarker.Show = True
            End If
       End If
    thanks for help.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: runtime error 3021

    This is wrong. if you dont use parenthesis with the Not then you are only using Not on the first eval criteria.

    Code:
    If ((Rss.EOF = False) And (Rss.BOF = False)) Then
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: runtime error 3021

    RobDog888:
    hi,i try the method as you guide,but the error remain the same.

    this is the current code:
    Code:
         If ((Rss.EOF = False) And (Rss.BOF = False)) Then
        MsgBox "no record"
        Else
         If Rss!seven < rs1!lcl Then error highlight at this line
                   MSChart1.Plot.SeriesCollection(5).SeriesMarker.Show = False
            Else
                    MSChart1.Plot.SeriesCollection(5).SeriesMarker.Show = True
            End If
       End If
    please help.thanks.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: runtime error 3021

    How many records are returned from your query?

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: runtime error 3021

    Recordcount may not bee of any value as it may not be supported.

    If Rss!seven < rs1!lcl Then

    Can generate many different errors like Type comparisons if one field is of a string and another is of date etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: runtime error 3021

    Hack:
    hi,Rss!seven is a plotting data point,will return many record from the query.rs1!Lcl is only return one data point for minimum scale Y from mschart.

    thanks for help.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: runtime error 3021

    You might want to fully qualify the objects instead of relying upon the defaults for evaluation.


    Code:
    If Rss.Fields("seven").Value < rs1.Fields("lcl").Value Then
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width