473,396 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Execute the sql inside the loop.

This code is supposed to insert all selected items from two list boxes into a table.
It only inserts one record regardless of how any are selected.

I've been told three times that I have to execute the SQL inside the loop. I have tried everything I can think of but I just don't get how to do it.


Expand|Select|Wrap|Line Numbers
  1.   Dim i As Variant
  2.     Dim x As Variant
  3.     Dim ParkValue As String, ConceptValue As String
  4.     Dim sqlApprove As String
  5.  
  6.  
  7. With Me.ConceptList
  8. For Each i In Me.ConceptList.ItemsSelected
  9. 'ConceptValue = ConceptValue & ", " & Me.ConceptList.ItemData(i)
  10. ConceptValue = Me.ConceptList.ItemData(i)
  11. Next i
  12.  
  13.  
  14.    With Me.ParkList
  15.     For Each x In Me.ParkList.ItemsSelected
  16.    ' ParkValue = ParkValue & ", " & Me.ParkList.ItemData(x)
  17.     ParkValue = Me.ParkList.ItemData(x)
  18.     Next x
  19.  
  20.     sqlApprove = "INSERT INTO TblFinal ( ParkID, ConceptID )  " & "VALUES('" & ParkValue & "','" & ConceptValue & "');"
  21.  
  22.     DoCmd.RunSQL sqlApprove
  23.  
  24. End With
  25.     End With
  26.  
  27. End Sub
Apr 19 '17 #1

✓ answered by NeoPa

DetrieZ:
I've been told three times that I have to execute the SQL inside the loop.
As there are two loops this explanation is a little short of helpful.

It seems to me, from your initial explanation sentence, that you'd need to have both loops and each would need some SQL executed within it to add all the items separately.

Unfortunately, Jet/ACE, which is what Access uses in DAO, doesn't have a syntax where you can add multiple records from values. Therefore each needs to be run separately.

At this point I'll stop as, looking at your SQL code it seems your question doesn't match what you're trying to do. Your code indicates that the two separate ListBoxes are actually connected in some way and one of each should end up in the destination table record. As nothing you've said explains, or even indicates that, we'll have to wait for you to fix the question to make proper sense before we can continue.

2 789
PhilOfWalton
1,430 Expert 1GB
Several questions spring to mind.

Where is the data coming from that populates your list box? presumably already from one or more tables?

Are you trying to add a "parallel" item from each list box to your new table?

What is supposed to happen if a different number of items is picked from each list box?

Have you thought of having a Yes/No field like ConceptSelected and ParkSelected in your tables, using the list boxes to set those values to true, and just using a query to display the results?

Phil
Apr 19 '17 #2
NeoPa
32,556 Expert Mod 16PB
DetrieZ:
I've been told three times that I have to execute the SQL inside the loop.
As there are two loops this explanation is a little short of helpful.

It seems to me, from your initial explanation sentence, that you'd need to have both loops and each would need some SQL executed within it to add all the items separately.

Unfortunately, Jet/ACE, which is what Access uses in DAO, doesn't have a syntax where you can add multiple records from values. Therefore each needs to be run separately.

At this point I'll stop as, looking at your SQL code it seems your question doesn't match what you're trying to do. Your code indicates that the two separate ListBoxes are actually connected in some way and one of each should end up in the destination table record. As nothing you've said explains, or even indicates that, we'll have to wait for you to fix the question to make proper sense before we can continue.
Apr 19 '17 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Aggelos | last post by:
Hi Guys!!! Thanks in advance for any kind of help about this problem. The problem: Acces Database One Table 'Orders' and second 'OrderItems' I want to export in txt file using FSO and...
0
by: Wilk Teverbaugh | last post by:
I've got an include file inside each page throughout my site. Inside this include file I'm running server.execute to include other pages based on a condition (userID). The problem has two parts-...
5
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform'...
6
by: dpswissboy | last post by:
I have a form with 30 input boxes named box1, box2, box3, etc. Instead of: var1 = Request.Form("box1") var2 = Request.Form("box2") etc. ..I am trying to collect the values in a loop statement...
1
by: winston.heng | last post by:
Hi, Thanks for reading this posting. I have been cracking my head on solving the infinite loop when i call the following section code. Any help or advise is greatly appreciated =D Thanks in...
2
by: akshata | last post by:
hi everyone, ive been asked to write a C code in which there is a while loop that keeps executing till a key is pressed.. ex while(1) { ...
3
by: fishnfrogs | last post by:
Hi, I can't figure out why this isn't working. I'm trying to loop through an array and do a mysql update. However, it doesn't work. for($i = 0; $i < $len; ++$i) { $param = $array . '%';...
4
by: dhruvc88 | last post by:
I have to write a C++ program that picks a random number between 0 and 49. If the number is even lets say 30, then the computer will display 30, 32, 34, 36... all the way till 100, if its odd lets...
1
by: soundararajanom | last post by:
hi iam using this code for datagrid row storage while check data is exist or not in DB sql server 2008 cmd.Parameters.Value = row.Cells.Value; cmd.Parameters.Value = row.Cells.Value;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.