Error 3421: "Data Type Conversion Error.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gilsygirl
    New Member
    • Sep 2007
    • 25

    Error 3421: "Data Type Conversion Error.

    Hi Guys

    Season greetings to everyone.

    Does anyone have an idea to this error message.

    Thanks
    gilsygirl
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    that simply means the target variable and the content does not match.

    Comment

    • gilsygirl
      New Member
      • Sep 2007
      • 25

      #3
      Originally posted by debasisdas
      that simply means the target variable and the content does not match.
      Hi thanks for the reply. how do i treat a text variable define as string. cos that is all i have done. but the error keeps coming from my sql statement.
      Is there any other suggestion u have.

      thanks

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Originally posted by gilsygirl
        Hi thanks for the reply. how do i treat a text variable define as string. cos that is all i have done. but the error keeps coming from my sql statement.
        Is there any other suggestion u have.

        thanks
        Kindly post what exactly youare trying to do and also the SQL statment that you are trying to execute.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Ignore me. I'm just registering an interest in this thread so I can tell when new messages are posted.

          Comment

          • gilsygirl
            New Member
            • Sep 2007
            • 25

            #6
            Originally posted by debasisdas
            Kindly post what exactly youare trying to do and also the SQL statment that you are trying to execute.
            Thanks for the reply

            I am trying to extra a record from a database using a combination of 3 of the fields in the database as a key. So i am querying them in an Sqlstmt variable use as the recordset. the fields in the database are define as text and in the vb form the variable agruments are define as string.

            So when i enter the variables on the form a second form should load displaying a record base on the variables passed provided it is in the database.

            this my code

            [code=vb]
            Public Function initdb()
            On Error GoTo error
            Set ws = DBEngine.Worksp aces(0)
            Set db = ws.OpenDatabase ("c:\resultchec ker.mdb")
            Set rs = db.OpenRecordse t("candres", dbOpenTable, dbReadOnly)
            Set rs1 = db.OpenRecordse t("subject", dbOpenTable, dbReadOnly)

            Exit Function
            End Function

            Sub cmdCheck_click( )

            Dim Exam_Sr As String
            Dim Exam_Yr As String
            Dim Cand_No As String
            Dim CentNo As String

            If rs.RecordCount = 0 Then Exit Sub
            rs.MoveFirst
            For i = 1 To rs.RecordCount ' Read all the records from database

            sqlStmt = "select * From candres where ExamSeries='" & Exam_Sr & "'and ExamYear='" & Exam_Yr & "'and CentNo='" & Cand_No & "'"
            rs.OpenRecordse t sqlStmt, db

            If Not (rs.EOF) Then
            frmCandResult.S how vbModal, Me
            Else
            MsgBox "sorry not a perfect match"
            End If

            CentNo = rs("CentNo")
            Cand_No = rs("IndexNo")
            Sex = rs("Sex")

            frmListing.Cent _No.Caption = rs("CentNo")
            frmListing.Cand _No.Caption = rs("IndexNo")
            frmListing.Cnd_ Name.Caption = rs("CandName")

            frmListing.Show vbModal, Me
            rs.MoveNext
            Next i
            End Sub[/code]
            Last edited by debasisdas; Dec 27 '07, 10:35 AM. Reason: Formatted using code tags.

            Comment

            • debasisdas
              Recognized Expert Expert
              • Dec 2006
              • 8119

              #7
              1. Which line of code is creating the error ?
              2. Why using a function with out any out type and nothing to return ?
              3. Why opening the same recordset twice from two different sources ?
              4. You have never called the function in the click event.
              5. Try to use ADO code , that is much more flexible.

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                My guess is that the CentNo field is numeric. If you have a close look at line 22 of the code, you'll see that it is being compared to variable Cand_No, delimited by quotes. This may be the source of the problem.

                Comment

                • gilsygirl
                  New Member
                  • Sep 2007
                  • 25

                  #9
                  Originally posted by debasisdas
                  1. Which line of code is creating the error ?
                  2. Why using a function with out any out type and nothing to return ?
                  3. Why opening the same recordset twice from two different sources ?
                  4. You have never called the function in the click event.
                  5. Try to use ADO code , that is much more flexible.
                  Thanks for the reply. I have been able to solve the query. I was passing the values to a different form then the required form. The new query is in the SQL statement. It is only picking the first record in the database.

                  Now I want to know which function you are referring to and where I am opening the recordset twice.
                  Thanks for the help, really appreciated.
                  gilsygirl newbie
                  Last edited by Killer42; Jan 3 '08, 02:50 AM.

                  Comment

                  • gilsygirl
                    New Member
                    • Sep 2007
                    • 25

                    #10
                    Originally posted by Killer42
                    My guess is that the CentNo field is numeric. If you have a close look at line 22 of the code, you'll see that it is being compared to variable Cand_No, delimited by quotes. This may be the source of the problem.
                    Thanks for the reply. I have been able to solve the query. My latest problem is the SQL statement. It is only picking the first record from the database.

                    This is the code:
                    [CODE=vb]
                    If rs.RecordCount = 0 Then Exit Sub
                    rs.MoveFirst
                    For i = 1 To rs.RecordCount ' Read all the records from database

                    sqlStmt = "select * From candres where ExamSeries='" & Exam_Sr & "'and ExamYear='" & Exam_Yr & "'and CentNo='" & Cand_No & "'"
                    rs.OpenRecordse t , sqlStmt

                    If Not (rs.EOF) Then
                    Call dispres
                    ' frmListing.Show vbModal, Me
                    Else
                    MsgBox "sorry not a perfect match"
                    End If
                    [/CODE]

                    What is wrong with this code?

                    Thanks for help it's really appreciated.
                    gilsygirl newbie
                    Last edited by Killer42; Jan 3 '08, 02:53 AM.

                    Comment

                    • Killer42
                      Recognized Expert Expert
                      • Oct 2006
                      • 8429

                      #11
                      Originally posted by gilsygirl
                      ... What is wrong with this code?
                      Not sure where to start. :)

                      But one thing to consider is that RecordCount may not be populated until the records are accessed. When you first open the recordset, I think it just holds 0 (if no records) or 1 (if any records). So you might see some improvement if you insert rs.MoveLast before line 2. Hm... or since you're immediately replacing rs anyway, maybe just change line 2 from MoveFirst to MoveLast.



                      I have a question. Is the recordset opened in line 5 supposed to contain the same records that were already in rs when we entered this part of the code? If so, there's no need to open anything, which I think is what Veena was getting at. You have the records there, just go ahead and use them.

                      Comment

                      Working...