Results 1 to 9 of 9

Thread: [RESOLVED] data type error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Resolved [RESOLVED] data type error

    can some one plz help me out the following code is giving an error as data type mismatch in crieteria expressionat line

    Set rs = conn.Execute(str)

    i am stuck plz help


    VB Code:
    1. ConvertTxtToExcel(lSourceFile As String)
    2.  
    3.   Set myXLObj = CreateObject("Excel.Application")
    4.     myXLObj.Visible = True ' to make the Excel app visible
    5.     On Error GoTo 0
    6.     With myXLObj
    7.     .Workbooks.OpenText FileName:=lSourceFile, DataType:=XLDELIMITED, _
    8.             TextQualifier:=XLDOUBLEQUOTE, semicolon:=True, _
    9.             FieldInfo:=Array(1, 2)
    10.         End With
    11.        
    12.         Dim i As Integer
    13.         Dim j As Integer
    14.         Dim a As String
    15.         Dim str As String
    16.         Dim k As String
    17.         i = 5
    18.         j = 1
    19.        While i < 180
    20.             While j <= 7
    21.             If j = 1 Then
    22.             k = "notice"
    23.             ElseIf j = 2 Then
    24.             k = "are1no"
    25.             ElseIf j = 3 Then
    26.             k = "Date"
    27.             ElseIf j = 4 Then
    28.             k = "pname"
    29.             ElseIf j = 5 Then
    30.             k = "IName"
    31.             ElseIf j = 6 Then
    32.             k = "tariff"
    33.             ElseIf j = 7 Then
    34.             k = "duty"
    35.             End If
    36.          
    37.         Set conn = New ADODB.Connection
    38.                 conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\excel\xldata.mdb;Persist Security Info=False")
    39.        
    40.         a = Cells(i, j).Value
    41.         'str = " update [data] set [" & k & "] = '" & a & "'  where [sno] = '" & i & "'"
    42.         str = "UPDATE [data] SET " & k & "= '" & a & "' WHERE sno = '" & i & "' "
    43.  
    44.     Set rs = conn.Execute(str)
    45.  
    46.                
    47.         j = j + 1
    48.         Wend
    49.  
    50.  i = i + 1
    51.  Wend
    52.  End Sub

  2. #2
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: data type error

    three things:
    1) what is ConvertTxtToExcel(lSourceFile As String)
    2) where have you declared con as a datatype?
    3) where have you declared rs as a datatype?
    4) where have you declared str as a datatype?

    I see that youre using ADODB, so 2 and 3 should be:
    VB Code:
    1. Dim con As ADODB.Connection, rs As ADODB.Recordset
    4 should be
    VB Code:
    1. Dim str As String

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Re: data type error

    VB Code:
    1. Option Explicit
    2. Dim rs As ADODB.Recordset
    3. Dim rs1 As ADODB.Recordset
    4. Dim conn As ADODB.Connection
    5. Dim conn1 As ADODB.Connection
    6. Dim conn2 As ADODB.Connection
    7. Public myXLObj As Object
    8.  
    9. Private Const XLDELIMITED = 1
    10. Private Const XLDOUBLEQUOTE = 1
    11. Private Const XLNORMAL = -4143
    12.  
    13. Private Sub CmdOpen_Click()
    14. 'MsgBox (Z)
    15. CommonDialog1.Filter = "Text Files (*.xls)|*.xls"
    16. CommonDialog1.ShowOpen
    17. ConvertTxtToExcel CommonDialog1.FileName
    18. CmdOpen.Enabled = False
    19. End Sub


    i have already declared those

  4. #4
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: data type error

    youre using a string called str in your update sql statement but do not see it below as declared anywhere.
    Quote Originally Posted by elixir_5000
    VB Code:
    1. Option Explicit
    2. Dim rs As ADODB.Recordset
    3. Dim rs1 As ADODB.Recordset
    4. Dim conn As ADODB.Connection
    5. Dim conn1 As ADODB.Connection
    6. Dim conn2 As ADODB.Connection
    7. Public myXLObj As Object
    8.  
    9. Private Const XLDELIMITED = 1
    10. Private Const XLDOUBLEQUOTE = 1
    11. Private Const XLNORMAL = -4143
    12.  
    13. Private Sub CmdOpen_Click()
    14. 'MsgBox (Z)
    15. CommonDialog1.Filter = "Text Files (*.xls)|*.xls"
    16. CommonDialog1.ShowOpen
    17. ConvertTxtToExcel CommonDialog1.FileName
    18. CmdOpen.Enabled = False
    19. End Sub


    i have already declared those

  5. #5
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: data type error

    also, with ConvertTxtToExcel(lSourceFile As String), you have the last line as End Sub but i do not see anywhere where you have opened the Sub. so shouldnt ConvertTxtToExcel(lSourceFile As String) be:
    VB Code:
    1. Private Sub ConvertTxtToExcel(lSourceFile As String)
    ?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Re: data type error

    Quote Originally Posted by BrailleSchool
    also, with ConvertTxtToExcel(lSourceFile As String), you have the last line as End Sub but i do not see anywhere where you have opened the Sub. so shouldnt ConvertTxtToExcel(lSourceFile As String) be:
    VB Code:
    1. Private Sub ConvertTxtToExcel(lSourceFile As String)
    ?

    i am sorry that is actually

    VB Code:
    1. Public Sub ConvertTxtToExcel(lSourceFile As String)

    that's why i have written end sub

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Re: data type error

    still there is the same error plz help

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Re: data type error

    Its Done The Data Type In The Data Base Was Not Same As That Of Variables

  9. #9
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [RESOLVED] data type error

    glad you got it fixed. also note that you can change the types in vbcode. for example, if you were using a string and you wanted to change to an integer, you can use CInt(). there are many of these change types in VB6.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width