Error : "statement invalid outside type block" need help here

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • squrel
    New Member
    • Jan 2008
    • 143

    Error : "statement invalid outside type block" need help here

    Hello All..
    I m having some problem here.. i m using VB6 and SQLServer 2000... i m getting this error " statement invalid outside type block"
    i m sending u the code and the bold line is where i m getting the error
    can anyone help me.. i dont knw whr i m doing mistake..
    thankx in advance




    Private Sub Toolbar1_Button Click(ByVal Button As MSComctlLib.But ton)

    ID As Integer
    On Error GoTo ChkErr

    Const FIND_BUTTON = 2


    Dim RsInd As New ADODB.Recordset
    ID = Val(MSHFlexGrid 1.TextMatrix(MS HFlexGrid1.RowS el, 1))


    If Button.Index = 3 Then ' ADD

    ID = 0

    Dim Rs As New ADODB.Recordset
    If Rs.State = adStateOpen Then Rs.Close
    Rs.Open ("SELECT * FROM casemaster"), Db, adOpenKeyset, adLockPessimist ic
    If Rs("StopTran"). Value = 1 Then
    MsgBox " Transactions Not Allowed "
    Rs.Close


    ElseIf Button.Index = 3 Then
    Mode = "Add"
    Call AddMode
    Call ClearControl
    End If

    End


    ElseIf Button.Index = 4 Then
    Mode = "View"
    frmCaseMaster.V isible = False
    Call ClearControl
    Call View


    ElseIf Button.Index = 5 Then

    If Rs.State = adStateOpen Then Rs.Close
    Rs.Open

    Mode = "Edit"
    'Frameview.Visi ble = False
    'cmdClearItem.V isible = True
    Call Edit

    End If

    If Button.Index = FIND_BUTTON Then
    frmFind.Show


    ElseIf Button.Index = 8 Then
    Unload Me

    ElseIf Button.Index = 6 Then ' Save
    Call save

    frmCaseMaster.V isible = False
    'SSTab1.Tab = 0

    ElseIf Button.Index = 7 Then ' Cancel
    If txtId.Text <> "" Then
    Toolbar1.Button s.Item(3).Enabl ed = True
    Toolbar1.Button s.Item(4).Enabl ed = True
    MsgBox " Id'" & txtId.Text & " ' Is canceled"

    Call Grid_Data
    frmCaseMaster.V isible = True
    Toolbar1.Button s.Item(7).Enabl ed = False ' Cancel

    End If
    End If
    'End If
    Exit Sub
    ChkErr:
    If Err.Number > 0 Then
    MsgBox Err.Number & vbNewLine & Err.Description
    Call ErrHand(Me.Capt ion, "Form_Initializ e")
    'Resume Next
    End If
    End Sub
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Declaration statements need "DIM",
    Change the line to:

    Dim ID As Integer

    Regards
    Veena

    Comment

    • squrel
      New Member
      • Jan 2008
      • 143

      #3
      Oh.. sorry i forgot tht.. bt now i m getting this error..
      "Item can not be found in the collection corresponding to the requested name or ordinal" and after pressing ok it says " path not found"
      wht i shld do now??
      thankx

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        What line are you getting Errors.?

        Regards
        Veena

        Comment

        • squrel
          New Member
          • Jan 2008
          • 143

          #5
          no line is giving me error.. when i press on the add button or any other button tht error is coming...

          Comment

          • squrel
            New Member
            • Jan 2008
            • 143

            #6
            still having error

            i have 8 buttons.. and using toolbar for tht...(Sort,Fin d,Add,View,Edit ,Save,Cancel,Ex it)

            when i m pressing on edit or view its telling me "the connection cannot be used to perform this operation. it is either closed or invalid in this context" and then after tht say " path not found" ..

            i dont knw if i m using the toolbar in a write way.. wld u plz check the code which i send it up and tel me whr is wrong..
            thank u very much

            Comment

            • QVeen72
              Recognized Expert Top Contributor
              • Oct 2006
              • 1445

              #7
              Hi,

              I Guess, "Db" is your Connection Object..
              In form_Load event, You have to Make Connection to the database, before you start querying..
              Check that Connection is made, and Database Path is selected appropriately..

              REgards
              Veena

              Comment

              • squrel
                New Member
                • Jan 2008
                • 143

                #8
                this is my form load


                Private Sub Form_Load()
                On Error GoTo ChkErr
                'Dim i As Integer

                Dim Rs As New ADODB.Recordset
                If Rs.State = adStateOpen Then Rs.Close
                Rs.Open ("select * from casemaster"), Db, adOpenKeyset, adLockPessimist ic


                Dim NewColumn As MSComctlLib.Col umnHeader
                'cmdShowList.Vi sible = True
                Toolbar1.Button s.Item(1).Enabl ed = True ' Sort
                Toolbar1.Button s.Item(2).Enabl ed = True ' Find
                Toolbar1.Button s.Item(3).Enabl ed = True ' Add
                Toolbar1.Button s.Item(4).Enabl ed = True ' View
                Toolbar1.Button s.Item(5).Enabl ed = True ' Edit
                Toolbar1.Button s.Item(6).Enabl ed = True ' Save
                Toolbar1.Button s.Item(7).Enabl ed = True ' Cancel
                Toolbar1.Button s.Item(8).Enabl ed = True ' Exit


                Call Grid_Data
                Exit Sub
                ChkErr:
                If Err.Number > 0 Then
                MsgBox Err.Number & vbNewLine & Err.Description
                Call ErrHand("frmCas eMaster", "Form_Load" )
                'Resume Next
                End If

                Grid_Data
                End Sub

                Comment

                • QVeen72
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1445

                  #9
                  Where is the Code to Connect to the database..?
                  I Did ask, Is connection made?
                  Also, remove error-handlers, to check if you have and runtime errors, in form load..

                  Regards
                  Veena

                  Comment

                  • squrel
                    New Member
                    • Jan 2008
                    • 143

                    #10
                    i m so confuse using this toolbar... i dont knw if i m using it rit... now my add is working bt my save is not... do u have any sample of toolbar code tht i can check it... or can u help me in any other way.. i have to make this
                    thankx

                    Comment

                    • QVeen72
                      Recognized Expert Top Contributor
                      • Oct 2006
                      • 1445

                      #11
                      Hi,

                      ToolBar Coding is OK, no problems with that..

                      In Save button, you are calling some procedure "Save",
                      What is the code there...?
                      Also Check the status of Recordset.. (If it is close, then Open..)

                      REgards
                      Veena

                      Comment

                      • squrel
                        New Member
                        • Jan 2008
                        • 143

                        #12
                        this is my code for save, view and edit
                        i m very sorry for trouble
                        and thank u very much for ur help


                        Public Function SaveCaseMaster( )

                        Db.Execute " Delete from casemaster where Id= '" & txtId.Text & "' "


                        Dim Rs As New ADODB.Recordset

                        If Rs.State = adStateOpen Then Rs.Close
                        Rs.Open ("CaseMaster "), Db, adOpenKeyset, adLockPessimist ic
                        With Rs
                        Rs.AddNew
                        .Fields("Id") = Val(txtId.Text)
                        .Fields("Descri ption") = Val(txtDescript ion.Text)
                        .Fields("casety pe") = Val(cmbCaseType .Text)
                        .Fields("caseId ") = Val(txtCaseId.T ext)
                        .Fields("compdi v") = Val(cmbCompDiv. Text)
                        .Fields("lodged by") = Val(cmblodgedby .Text)
                        .Fields("lodged date") = Format(Date, "DD-MMM-YYYY")
                        .Fields("sectio n") = Val(txtSec.Text )
                        .Fields("courtI d") = Val(txtCourtId. Text)
                        .Fields("fileno ") = Val(txtFileNo.T ext)
                        .Fields("party" ) = Val(cmbParty.Te xt)
                        .Fields("EntryD ate") = Format(Date, "DD-MMM-YYYY")
                        .Fields("closed ate") = Format(Date, "DD-MMM-YYYY")
                        .Update
                        End With
                        Rs.Close


                        End Function





                        Public Sub View()

                        Toolbar1.Button s.Item(1).Enabl ed = False ' Add
                        Toolbar1.Button s.Item(2).Enabl ed = False ' View
                        Toolbar1.Button s.Item(3).Enabl ed = False ' Sort
                        Toolbar1.Button s.Item(4).Enabl ed = True ' Edit
                        Toolbar1.Button s.Item(5).Enabl ed = False ' Save
                        Toolbar1.Button s.Item(6).Enabl ed = True ' Copy
                        Toolbar1.Button s.Item(7).Enabl ed = True ' Cancel

                        Call Grid_Data
                        frmCaseMaster.V isible = True

                        Call Disable


                        txtId.Text = Val(txtId.Text)
                        txtDescription. Text = Val(txtDescript ion.Text)
                        cmbCaseType.Tex t = Val(cmbcasetyp. Text)
                        txtCaseId.Text = Val(txtCaseId.T ext)
                        cmbCompDiv.Text = Val(cmbCompDiv. Text)
                        cmblodgedby.Tex t = Val(cmblodgedby .Text)
                        txtSec.Text = Val(txtSec.Text )
                        txtCourtId.Text = Val(txtCourtId. Text)
                        txtFileNo.Text = Val(txtFileNo.T ext)
                        cmbParty.Text = Val(cmbParty.Te xt)
                        txtCaseId.Text = Val(txtCaseId.T ext)


                        End Sub



                        Public Sub Edit()
                        Dim Rs1 As New ADODB.Recordset
                        If Rs1.State = adStateOpen Then Rs1.Close
                        Rs1.Open ("SELECT * from CaseMaster where Id = '" & ID & "'"), Db, adOpenKeyset, adLockPessimist ic
                        If Not Rs1.EOF And Not Rs1.BOF Then
                        Toolbar1.Button s.Item(1).Enabl ed = False ' Add
                        Toolbar1.Button s.Item(2).Enabl ed = False ' View
                        Toolbar1.Button s.Item(3).Enabl ed = False ' Sort
                        Toolbar1.Button s.Item(4).Enabl ed = False ' Edit
                        Toolbar1.Button s.Item(5).Enabl ed = True ' Save
                        Toolbar1.Button s.Item(6).Enabl ed = False ' Copy
                        Toolbar1.Button s.Item(7).Enabl ed = False ' Cancel
                        Toolbar1.Button s.Item(8).Enabl ed = False 'Find
                        Toolbar1.Button s.Item(8).Enabl ed = False 'Exit
                        ' txtItemSrl.Text = Val(txtItemSrl. Text) + 1
                        Call Enable
                        Else
                        MsgBox " Cannot Edit"
                        frmCaseMaster.V isible = False

                        End If
                        End Sub

                        Comment

                        • QVeen72
                          Recognized Expert Top Contributor
                          • Oct 2006
                          • 1445

                          #13
                          Hi,

                          In your toolbar Click event change this line of code:


                          ElseIf Button.Index = 6 Then
                          Call SaveCaseMaster


                          At the top of your Form's Code window, type this :
                          Option Explicit

                          Most of the Compile errors can be caught..

                          REgards
                          Veena

                          Comment

                          • squrel
                            New Member
                            • Jan 2008
                            • 143

                            #14
                            those lines are already there.. i have done tht...
                            wld u plz just tel me tht is my code is rit for save, edit and view???.... thn i can work on it..
                            thank u very much :)

                            Comment

                            • QVeen72
                              Recognized Expert Top Contributor
                              • Oct 2006
                              • 1445

                              #15
                              Hi,

                              Your Code seems Quite right..
                              Note, you have Procedure names like "Save", "Edit", "Enable"...
                              These are Fixed Keywords.. Never use such words,,
                              Its a bit confusing, when you debug,
                              Cant you Change them to somewhat other names like "RecSave", "RecEdit"..

                              Regards
                              Veena

                              Comment

                              Working...