Results 1 to 11 of 11

Thread: Quick, Easy question.....

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    alb, nm 87112
    Posts
    56
    I've got an SQL statement within a For....Next loop. Should the SQL be executed after each loop, or once after and outside of the loop?


    Thanks!

  2. #2
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    It'll be executed for each loop, surely?

  3. #3
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    It kinda depends on what it does, and what you want to achieve..?!
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    alb, nm 87112
    Posts
    56
    It's just a simple append statement. Pasting 100 records from one Access table to another. I'm going to try to paste the code below. Does the execute statement come before or after the Next?

    code

    Dim SQL as String
    Dim LanceJet as Database

    For X = 1 To 100

    SQL = "INSERT INTO SiteInfo ( SiteName, MainURL, Signups )"
    SQL = "SELECT [WM Site Info].SiteName, [WM Site Info].MainURL, [WM Site Info].Signups"
    SQL = "From [WM Site Info]"
    SQL = "ORDER BY [WM Site Info].Signups DESC;"

    Next



  5. #5
    New Member
    Join Date
    Mar 2000
    Posts
    14
    I believe you'll have to do an execute command before the next command.


    FireBeast

    PS just out of interest, why don't you do an insert sql with a where clause which will pick up all records which match your selected criteria?

  6. #6
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    Can do either.
    Would probably be quicker to append them together and run after the Next.

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    alb, nm 87112
    Posts
    56

    One more question.....

    I'm getting a syntax error in the SQL code. Can you take a look at it above, and let me know what I've done wrong?

    Thanks

  8. #8
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    Looks like you need to join the SQL together, use "& _" at the end of the 1st 3 lines, remove the SQL = of the last 3 lines. Don't forget to put spaces before each closing double quote.

  9. #9
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    Hi, Dan0331.


    You didn't supply any values to insert.
    The syntax should be:
    SQL = "INSERT INTO SiteInfo ( SiteName, MainURL, Signups) Values (SELECT [WM Site Info].SiteName, [WM Site Info].MainURL, [WM Site Info].Signups From [WM Site Info]"

    Larisa

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    alb, nm 87112
    Posts
    56
    Hey Bonker,

    I'm now getting an error stating that the MicroSoft Jet DB cannot find the input query for the following.

    SQL = "ORDER BY [WM Site Info].Signups"

    I've also tried it with a space at the end:

    SQL = "ORDER BY [WM Site Info].Signups "

    This is the last line of the SQL statement so I know I don't need the &_ at the end.

    Any suggestions?

    Thanks for your help.


  11. #11
    Lively Member
    Join Date
    Apr 2000
    Location
    Rafaela (Argentine)
    Posts
    107
    Try this one:

    SQL = "INSERT INTO SiteInfo (SiteName, MainURL, Signups) "
    SQL = SQL & "SELECT [WM Site Info].SiteName, [WM Site Info].MainURL, [WM Site Info].Signups "
    SQL = SQL & "From [WM Site Info] "
    SQL = SQL & "ORDER BY [WM Site Info].Signups DESC;"

    or

    SQL = "INSERT INTO SiteInfo (SiteName, MainURL, Signups) " & _
    "SELECT [WM Site Info].SiteName, [WM Site Info].MainURL, [WM Site Info].Signups " & _
    "From [WM Site Info] " & _
    "ORDER BY [WM Site Info].Signups DESC;"

    Rgds.

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