type mismatch error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • makmax
    New Member
    • Nov 2007
    • 3

    type mismatch error

    Hi, I'm using VB6 and when trying to pass the selection of the listbox in one form to a textbox in another form I get the mismatch error code 13, though the textbox is a string and the passing parameter is a string as well. I'm using this code to pass the parameter:
    [CODE=vb]Private Sub Select_cmd_Clic k()
    passpara = emp_list
    Forms!PerData!P ersonal(1) = passpara
    Unload Me
    End Sub[/CODE]
    Last edited by Killer42; Nov 19 '07, 01:53 AM. Reason: Added CODE=vb tag
  • YarrOfDoom
    Recognized Expert Top Contributor
    • Aug 2007
    • 1243

    #2
    Maybe if you can provide us with the piece of code that handles that, it would be easier to help.

    Yarr

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Yes, as Yarr says, I think we need you to provide us with more detail, especially details concerning the declaration of things like passpara. Also, which line produces the error? And what do you see if you examine the variables/properties at that point?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        P.S. If passpara is a Variant (or, heaven forbid, you are just allowing VB to create it automatically) and emp_list is a control (listbox?) then you may be trying to pass the actual control rather than a string.

        If this is the case, then I would suggest the following...
        1. Declare passpara as a String.
        2. Place Option Explicit at the start of all forms and modules, to force the declaration of all variables. Simply allowing VB to create them on the fly is fraught with problems. For one thing, you can never tell if you mistype a variable name - it just creates a new one and leaves you wondering where your value went.
        3. For all the same reasons, go to Tools | Options | Editor and turn on the Require Variable Declaration option.

        Comment

        • AHMEDYO
          New Member
          • Nov 2007
          • 112

          #5
          HI...

          i think the problem isnt assign value from Passpara Variable, if you try this line you will get Error too

          [CODE=vb] Dim FormObj as Form
          Set FormObj=Forms!P erData 'TypeMismatch Error : 13
          [/CODE]

          Then i think the error within the return type from Forms "!" Operator, and i dont know why you use this style because you exactly know what form you will get data from!!

          this style will work

          [CODE=vb]PerData.Persona l(1)=Passpara[/CODE]

          Best Regards

          Comment

          • makmax
            New Member
            • Nov 2007
            • 3

            #6
            Hi,
            Thank you all for your help, I'm sorry I didn't provide you with details. I could solve the problem by typing the following line

            Search_Form.Sho w vbModal <==== in the first form

            which opens the search form, then I could pass the string of the pass_para to the first form, otherwise the error comes.

            Thanks all

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              It sounds to me as though you're not solving the problem, merely avoiding it.

              I suppose if it works, that's the important thing. But what happens next time you run into a similar problem? It's generally better if you understand the situation, rather than just dodging it.

              Comment

              • makmax
                New Member
                • Nov 2007
                • 3

                #8
                Hi,

                You may be right Killer42, but I couldn't find other solution it is like this:
                In the first form I have this code:

                Search_Form.Sho w <=== first line
                Personal(1) = passpara

                Set db = OpenDatabase("d :\medical\medic al assist2000.mdb" )
                Set rs = db.OpenRecordse t("select * from PersonalData where emp_name = " & "'" & passpara & "'")

                And so on...

                If I don't add the option vbModal to the first line, the code keeps on execution on form1 though form2 is on the screen and so I get Null value for the variable passpara which takes the value from the listbox in form2..

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  So in other words, you need to put off using the data from form2 until it has loaded and populated everything. That shouldn't be too hard.

                  Oh well, if showing it modally works, you might as well do that, huh.

                  Comment

                  Working...