Results 1 to 6 of 6
  1. #1
    printsol is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2021
    Posts
    33

    Loop for insert query


    hi there
    can any body help me regarding this

    Dim LCounter As Integer


    For LCounter = 1 To 3

    DoCmd.RunSQL "INSERT INTO MarksDistribution ([class]) VALUES (1)"
    MsgBox (LCounter)

    Next LCounter

    above query work fine for hard coded value but


    i want LCounter as Value to insert in table instead of 1


    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Try

    DoCmd.RunSQL "INSERT INTO MarksDistribution ([class]) VALUES (" & LCounter & ")"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    printsol is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2021
    Posts
    33
    Thanks its work fine
    one more thing please
    how can i concatenate string along LCounter
    like

    DoCmd.RunSQL "INSERT INTO MarksDistribution ([class]) VALUES ("a"&" & LCounter & ")"

    ?

  4. #4
    printsol is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2021
    Posts
    33
    Thanks Dear

    let me know how do i make this thread "Solved"


    i did figure out
    DoCmd.RunSQL "INSERT INTO MarksDistribution ([examtype]) VALUES ('a' & " & LCounter & ")"


    I really Thankful to you

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I'm surprised that worked but you can mark it solved in Thread Tools at the top of the thread.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Why not just put 3 in on it's own?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Loop for DoCmd.RunSQL ("INSERT INTO tbl
    By undertm in forum Programming
    Replies: 4
    Last Post: 05-31-2019, 11:17 AM
  2. Replies: 9
    Last Post: 03-07-2017, 02:49 PM
  3. Replies: 2
    Last Post: 05-14-2015, 12:24 PM
  4. Replies: 5
    Last Post: 12-21-2013, 06:26 PM
  5. Replies: 3
    Last Post: 03-10-2013, 07:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums