Please help me soon

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

    #1

    Please help me soon

    I have 2 forms in my project I am using vb. One form is sales and other is MainConn

    I have written one function in MainConn form.

    Code:
    Dim ctl as control
    Public Sub Reset_Fields(ByVal frm As Form)
        For Each objctl In frm.Controls
            If UCase(TypeName(objctl)) = "TEXTBOX" Then
                       objctl.Text = ""
            End If
        Next
    End Sub
    I am calling this function from sales form by writting code:
    frmMainConn.Res et_Fields(Me)

    But above code doesnot work.
    1) I am getting an error:Type mismatch.
    2) When i type objctl in Reset_Fields function, pop up window doesnt come i.e. Text Property.

    What is the solution? Can u tell me what is the correct code.Plz help me soon.
    Last edited by willakawill; Mar 15 '07, 03:21 PM. Reason: You must use code tags
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Code:
    Dim ctl as control
    If the purpose of this declaration is only to have a control object for the sub then you should declare this object inside the sub
    Code:
    Public Sub Reset_Fields(ByVal frm As Form)
    There is no need to have a form as a parameter because you are calling this sub from the same form therefore:
    Code:
    Private Sub Reset_Fields()
    will work unless you plan to use this code for other forms
    Code:
    For Each objctl In frm.Controls
    We don't know where this object 'objctl' comes from. I assume you are putting together various pieces of code that you have picked up on TSDN from answers to your other questions which is why, from your point of view, getting others to write your code for you does not work. Having declared ctl, you should continue to use that in your sub
    Code:
    If UCase(TypeName(ctl)) = "TEXTBOX" Then
    ctl.Text = ""
    End If
    So you can call this function like this:
    Code:
    Reset_Fields
    You have posted enough here to understand that you must use code tags

    Comment

    • Shailja
      New Member
      • Feb 2007
      • 123

      #3
      Originally posted by willakawill
      Code:
      Dim ctl as control
      If the purpose of this declaration is only to have a control object for the sub then you should declare this object inside the sub
      Code:
      Public Sub Reset_Fields(ByVal frm As Form)
      There is no need to have a form as a parameter because you are calling this sub from the same form therefore:
      Code:
      Private Sub Reset_Fields()
      will work unless you plan to use this code for other forms
      Code:
      For Each objctl In frm.Controls
      We don't know where this object 'objctl' comes from. I assume you are putting together various pieces of code that you have picked up on TSDN from answers to your other questions which is why, from your point of view, getting others to write your code for you does not work. Having declared ctl, you should continue to use that in your sub
      Code:
      If UCase(TypeName(ctl)) = "TEXTBOX" Then
      ctl.Text = ""
      End If
      So you can call this function like this:
      Code:
      Reset_Fields
      You have posted enough here to understand that you must use code tags
      No, I have declared the procedure, Reset_Fields in module. And i am calling this sub from other form. When I call the sub by Reset_Fields(Me ) from other form, it gives an error that type mismatch. So how to call an object of the form?

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Tell me about ctl and objctl

        Comment

        • Shailja
          New Member
          • Feb 2007
          • 123

          #5
          When you use 'Me' as a parameter you are sending a pointer to the form or, in visual basic language, a reference to the form. Therefore you must pass this parameter by reference or 'ByRef'. So change this:
          Code:
          Public Sub Reset_Fields(ByVal frmobj As Form)
          to this:
          Code:
          Public Sub Reset_Fields(ByRef frmobj As Form)

          Comment

          • willakawill
            Top Contributor
            • Oct 2006
            • 1646

            #6
            Originally posted by Shailja
            When you use 'Me' as a parameter you are sending a pointer to the form or, in visual basic language, a reference to the form. Therefore you must pass this parameter by reference or 'ByRef'. So change this:
            Code:
            Public Sub Reset_Fields(ByVal frmobj As Form)
            to this:
            Code:
            Public Sub Reset_Fields(ByRef frmobj As Form)
            Sorry I edited your post by mistake instead of replying to it. Anyway the answer is there. Good luck

            Comment

            Working...