Problem in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shailja
    New Member
    • Feb 2007
    • 123

    Problem in VB

    Hi,

    Code:
    Dim objtmp As Control
    
    Public Function OnLoad(ByVal frmobj1 As Form)
        For Each objtmp In frmobj1.Controls
            If TypeOf objtmp Is TextBox Then
              objtmp.Enabled = False   
            End If
        Next tmp
    End Function
    I have created this function in my project. But it doesnt work. What is wrong with the above code? Please tell me as soon as possible.

    Thanks
    Last edited by willakawill; Feb 26 '07, 04:54 PM. Reason: please use code tags when posting code
  • vijaydiwakar
    Contributor
    • Feb 2007
    • 579

    #2
    Originally posted by Shailja
    Hi,

    Dim objtmp As Control

    Public Function OnLoad(ByVal frmobj1 As Form)
    For Each objtmp In frmobj1.Control s
    If TypeOf objtmp Is TextBox Then
    objtmp.Enabled = False
    End If
    Next tmp
    End Function

    I have created this function in my project. But it doesnt work. What is wrong with the above code? Please tell me as soon as possible.

    Thanks
    just one extra word
    replace next tmp by next or next objtmp

    Comment

    • Shailja
      New Member
      • Feb 2007
      • 123

      #3
      Originally posted by vijaydiwakar
      just one extra word
      replace next tmp by next or next objtmp

      Still its not working. Plz suggest me how to code it in other way?

      Comment

      • vijaydiwakar
        Contributor
        • Feb 2007
        • 579

        #4
        Originally posted by Shailja
        Still its not working. Plz suggest me how to code it in other way?
        the code is write to call the function u have to write onload me this will solve the problem
        or
        put this code in form and call in formload evnt
        Code:
        Private Sub Form_Load()
        LockTextBoxes
        End Sub
        
        Private Sub LockTextBoxes()
        Dim ctrl As Control
        For Each ctrl In Me
            If TypeOf ctrl Is TextBox Then ctrl.Enabled = False
        Next
        End Sub

        Comment

        • hariharanmca
          Top Contributor
          • Dec 2006
          • 1977

          #5
          Originally posted by Shailja
          Still its not working. Plz suggest me how to code it in other way?
          Code:
          Dim objtmp as Control
          Public Function OnLoad(ByVal frmobj1 As Form)
          For Each objtmp In frmobj1
          If TypeOf objtmp Is TextBox Then
          objtmp.Enabled = False 
          End If
          Next 
          End Function

          Just Try this

          Comment

          • Shailja
            New Member
            • Feb 2007
            • 123

            #6
            Originally posted by vijaydiwakar
            the code is write to call the function u have to write onload me this will solve the problem
            or
            put this code in form and call in formload evnt
            Code:
            Private Sub Form_Load()
            LockTextBoxes
            End Sub
            
            Private Sub LockTextBoxes()
            Dim ctrl As Control
            For Each ctrl In Me
                If TypeOf ctrl Is TextBox Then ctrl.Enabled = False
            Next
            End Sub


            See, I have two forms in my project
            1) frmSales
            2) frmConn

            From frmSales form, I need to call procedure written in frmConn. Below is the procedure in frmConn.

            Code:
            Dim objctl As Control
            Public Sub OnLoad(ByVal frmobj1 As Form)
                For Each objctl In frmobj1.Controls
                    If TypeOf objctl Is TextBox Then
                         objctl.Enabled = False
                    End If
                Next
            End Sub
            Now from frmSales form I want to call this procedure. I have written following statment to call above procedure.

            Code:
            frmConn.OnLoad(Me)
            When I run the form frmSales, Type Mismatch error is coming. What is the correct code to call procedure? What do i need to write to instead of Me.
            Plz help me out.
            Last edited by willakawill; Feb 26 '07, 04:54 PM. Reason: please use code tags when posting code

            Comment

            • vijaydiwakar
              Contributor
              • Feb 2007
              • 579

              #7
              Originally posted by Shailja
              See, I have two forms in my project
              1) frmSales
              2) frmConn

              From frmSales form, I need to call procedure written in frmConn. Below is the procedure in frmConn.

              Dim objctl As Control
              Public Sub OnLoad(ByVal frmobj1 As Form)
              For Each objctl In frmobj1.Control s
              If TypeOf objctl Is TextBox Then
              objctl.Enabled = False
              End If
              Next
              End Sub

              Now from frmSales form I want to call this procedure. I have written following statment to call above procedure.

              frmConn.OnLoad( Me)

              When I run the form frmSales, Type Mismatch error is coming. What is the correct code to call procedure? What do i need to write to instead of Me.
              Plz help me out.
              See first of all the code is right so i'm not getting any error ok.
              Secondly if u like to make such function then just make these function global i.e. place them in module as
              in frmSales just call Onload me
              put the code in module1
              Code:
               
              Public Sub OnLoad(ByVal frmobj1 As Form)
              Dim objctl As Control
              For Each objctl In frmobj1.Controls
              If TypeOf objctl Is TextBox Then
              objctl.Enabled = False
              End If
              Next
              End Sub
              this will generalise the procedure for any form
              k.........

              Comment

              • sukeshchand
                New Member
                • Jan 2007
                • 88

                #8
                Dear Friend Try this code.

                Code:
                Public Sub OnLoad(ByVal frmobj1 As Form)
                Dim objctl As Control
                For Each objctl In frmobj1.Controls
                        If UCase(TypeName(objctl))="TEXTBOX" Then
                                  objctl.Enabled = False
                         End If
                Next
                End Sub

                Comment

                • Shailja
                  New Member
                  • Feb 2007
                  • 123

                  #9
                  Originally posted by sukeshchand
                  Dear Friend Try this code.

                  Code:
                  Public Sub OnLoad(ByVal frmobj1 As Form)
                  Dim objctl As Control
                  For Each objctl In frmobj1.Controls
                          If UCase(TypeName(objctl))="TEXTBOX" Then
                                    objctl.Enabled = False
                           End If
                  Next
                  End Sub

                  Thanks for the code but it doesnt work.

                  Comment

                  • vijaydiwakar
                    Contributor
                    • Feb 2007
                    • 579

                    #10
                    Show thy code

                    Comment

                    • Shailja
                      New Member
                      • Feb 2007
                      • 123

                      #11
                      Originally posted by sukeshchand
                      Dear Friend Try this code.

                      Code:
                      Public Sub OnLoad(ByVal frmobj1 As Form)
                      Dim objctl As Control
                      For Each objctl In frmobj1.Controls
                              If UCase(TypeName(objctl))="TEXTBOX" Then
                                        objctl.Enabled = False
                               End If
                      Next
                      End Sub
                      An error is coming when I execute the statment
                      frmMain.OnLoad( Me)
                      I am writting this statment into other form and calling function written into frmMain. Whats wrong with above statment?

                      Comment

                      • vijaydiwakar
                        Contributor
                        • Feb 2007
                        • 579

                        #12
                        The codes given are absolutly correct just show how and where did u write d code paste code

                        Comment

                        • Shailja
                          New Member
                          • Feb 2007
                          • 123

                          #13
                          Originally posted by vijaydiwakar
                          The codes given are absolutly correct just show how and where did u write d code paste code

                          The statment I am writting on Form load event of frmSales. In this form i am calling function written in frmMain

                          Code:
                          Private Sub Form_Load()
                          frmMain.OnLoad (Me)
                          End Sub
                          Last edited by willakawill; Feb 26 '07, 04:55 PM. Reason: please use code tags when posting code

                          Comment

                          • Farina
                            New Member
                            • Feb 2007
                            • 1

                            #14
                            code posted without explanation or comments.
                            Last edited by willakawill; Feb 26 '07, 04:57 PM. Reason: please do not post code without explanation or comments

                            Comment

                            • vijaydiwakar
                              Contributor
                              • Feb 2007
                              • 579

                              #15
                              Originally posted by Shailja
                              The statment I am writting on Form load event of frmSales. In this form i am calling function written in frmMain

                              Private Sub Form_Load()
                              frmMain.OnLoad (Me)
                              End Sub
                              which form is opened first ? are u showing frmsales modally?
                              now tell me the execution flow of thy programm

                              Comment

                              Working...