Results 1 to 8 of 8

Thread: Need help finding error in code here...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Need help finding error in code here...

    The error occurs on the following line:
    VB Code:
    1. For x = 0 To File1.ListCount - 1

    Here's the code:
    VB Code:
    1. Private Sub Command2_Click()
    2. 'Dim stuff here
    3. Dim x As Integer
    4. Dim table As String
    5. Dim fname As String
    6. Dim strFilepath As String, strFileName As String, _
    7. strFileSize As String, strArtist As String, _
    8. strTitle As String, strAlbum As String, strTrack As String, _
    9. strFrequency As String, strBitrate As String, _
    10. strLength As String
    11.  
    12.  
    13. 'add the new category to the listbox
    14. lstCategories.AddItem txtcategory.Text
    15.  
    16. 'Create a new table in the Database for the category
    17. Call ADOCreateTable
    18.  
    19. 'connect to the database
    20. Dim Cnn As ADODB.Connection
    21. Dim SQL As String
    22. Set Cnn = New ADODB.Connection
    23. Cnn.Open ConnectionString:="Provider=Microsoft.Jet.OLEDB.4.0;" & _
    24.       "Data Source= c:\windows\system\kamo.mdb;"
    25.  
    26. 'set table = to the category added
    27. table = txtcategory.Text
    28.  
    29. 'Loop through the filelistbox getting info on the files
    30. For x = 0 To File1.ListCount - 1
    31.     fname = File1.Path & "\" & File1.List(x)
    32.     ReadMP3 fname, True, True
    33.    
    34. 'Store the info as strings
    35.     strFilepath = fname
    36.     strFileName = File1.List(x)
    37.     strFileSize = FileLen(fname)
    38.     strArtist = GetMP3Info.Artist
    39.     strTitle = GetMP3Info.Songname
    40.     strAlbum = GetMP3Info.Album
    41.     strTrack = GetMP3Info.Track
    42.     strFrequency = GetMP3Info.Frequency
    43.     strBitrate = GetMP3Info.bitrate
    44.     strLength = GetMP3Info.Duration
    45.    
    46.    
    47. 'Use SQL to insert the information in the strings into the table
    48. SQL = "INSERT into Table (Filepath,Filename,Filesize,Artist, _
    49. Title,Album,Frequency,Bitrate,Length,Track#) _
    50. VALUES ('" & strFilepath & "','" & strFileName & "', _
    51. '" & strFileSize & "','" & strArtist & "','" & strTitle & "', _
    52. '" & strAlbum & "','" & strTrack & "','" & strFrequency & "', _
    53. '" & strBitrate & "','" & strLength & "')"
    54. Cnn.Execute SQL
    55.  
    56. Next
    57.  
    58.  
    59. 'Update the combocategory on the main form
    60. Call WriteTextFile
    61.  
    62. End Sub

  2. #2
    Addicted Member Pickler's Avatar
    Join Date
    May 2001
    Location
    nffanb
    Posts
    248
    What is the error?

  3. #3
    Addicted Member Rikk's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta
    Posts
    131
    yeah, whats the error?
    Rikk =\=
    Starcraft, Protoss Scout Driver!

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Fixed that....New Error :)

    I forgot to specify the File1.Path=!

    Now I'm getting an error on SQL Insert part. On this Line:
    VB Code:
    1. Cnn.Execute SQL

    And yes I know that in the post the SQL line is messed up, but I made it so you wouldn't have to scroll over. I think the problem is:
    VB Code:
    1. SQL = "INSERT into Table

    TABLE in this line is a variable, not the name of the table I want to open. Should I have it in quotes or something? I have to do this because the table name will vary.

  5. #5
    Addicted Member Rikk's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta
    Posts
    131
    What does the error say?
    Rikk =\=
    Starcraft, Protoss Scout Driver!

  6. #6
    Addicted Member Pickler's Avatar
    Join Date
    May 2001
    Location
    nffanb
    Posts
    248
    Yep, you will
    ie:
    VB Code:
    1. Dim myTable as String
    2. Dim SQL as String
    3.  
    4. myTable="WhateverTable"
    5. SQL = "INSERT into " & myTable & " the rest....."

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    SQL syntax error on that last line I posted

    n/m

  8. #8
    Addicted Member Rikk's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta
    Posts
    131
    Beware of inserting data like this:

    VB Code:
    1. VALUES ('" & strFilepath & "','" & strFileName & "'

    If the strFilePath var contains a single quote in it, it will fail. Use REPLACE on EVERY var to change all single quotes to two single quotes. It will go in the database as only one.

    Like this...

    VB Code:
    1. VALUES ('" & Replace(strFilepath,"'","''") & "','" & Replace(strFileName,"'","''") & "'
    Rikk =\=
    Starcraft, Protoss Scout Driver!

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