473,776 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Do Until Loop Help!

129 New Member
Hello, i am wanting a Loop procedure to check details of all the multiple rows with the following D-LOOKUP procedures;
Expand|Select|Wrap|Line Numbers
  1. [*]StkID.Value = DLookup("[StkID]", "stkmas", "[StkShortDesc] = Forms![frmPreSOLine]![StkShortDesc]")[*]Price.Value = DLookup("[SalePrice1]", "primas", "[StkID] = Forms![frmPreSOLine]![StkID]")
For the Loop procedure to work i have used the following code:
Expand|Select|Wrap|Line Numbers
  1. Dim dbs As Database
  2. Dim rst As Recordset
  3. Dim Reply As String
  4. Dim strSQL As String
  5.  
  6. Set dbs = CurrentDb
  7. Set rst = dbs.OpenRecordset("SELECT * FROM preordlin")
  8. strSQL = "INSERT INTO stkmas ([StkShortDesc],[Width],[Depth],[Height]) SELECT [StkShortDesc],[Width],[Depth],[Height] FROM preordlin WHERE IsNull(StkID)"
  9.  
  10. Do Until rst.EOF
  11.     StkID.Value = DLookup("[StkID]", "stkmas", "[StkShortDesc] = Forms![frmPreSOLine]![StkShortDesc]")
  12.     Price.Value = DLookup("[SalePrice1]", "primas", "[StkID] = Forms![frmPreSOLine]![StkID]")
  13.     rst.MoveNext
  14. Loop
  15.  
  16. If IsNull(StkID) Then
  17.     Reply = MsgBox("There are Stock Items that present that do not belong to our existing Stock files. Would you like to ADD then?", vbYesNo, "None Existent Stock Details!")
  18.     If Reply = vbYes Then
  19.         DoCmd.RunSQL strSQL
  20.     Else
  21.     End If
  22. Else
  23. End If
The only problem is when i click on the button to execute this procedure, it works but only works on 1 row at a time and you have to keep clicking the button on all the rows of data. Is there a way that does it for all of them at once?

Please help!

Thanks in advance.

Chris
Aug 10 '08 #1
2 3162
ADezii
8,834 Recognized Expert Expert
Just subscribing, I took the liberty of rewriting your code for the sake of clarity. I realize that you are new to this, but in the future, kindly use the Code Tags for obvious reasons. I really don't have the time now to help you with a Reply to this Thread, but I'll check back later and in the meantime, I'm sure someone will provide you with assistance.
  • StkID.Value = DLookup("[StkID]", "stkmas", "[StkShortDesc] = Forms![frmPreSOLine]![StkShortDesc]")
  • Price.Value = DLookup("[SalePrice1]", "primas", "[StkID] = Forms![frmPreSOLine]![StkID]")

'For the Loop procedure to work i have used the following code:

Expand|Select|Wrap|Line Numbers
  1. Dim dbs As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Dim Reply As String
  4. Dim strSQL As String
  5.  
  6. Reply = "There are Stock Items that present that do not belong to our " & _
  7.         "existing Stock files. Would you like to ADD then?"
  8.  
  9. Set dbs = CurrentDb
  10. Set rst = dbs.OpenRecordset("SELECT * FROM preordlin")
  11. strSQL = "INSERT INTO stkmas ([StkShortDesc],[Width],[Depth],[Height]) SELECT " & _
  12.          "[StkShortDesc],[Width],[Depth],[Height] FROM preordlin WHERE IsNull(StkID)"
  13.  
  14. Do Until rst.EOF
  15.   StkID.Value = DLookup("[StkID]", "stkmas", "[StkShortDesc] = Forms![frmPreSOLine]![StkShortDesc]")
  16.   Price.Value = DLookup("[SalePrice1]", "primas", "[StkID] = Forms![frmPreSOLine]![StkID]")
  17.     rst.MoveNext
  18. Loop
  19.  
  20. If IsNull(StkID) Then
  21.   Reply = MsgBox(Reply, vbYesNo, "None Existent Stock Details!")
  22.   If Reply = vbYes Then
  23.     DoCmd.RunSQL strSQL
  24.   Else
  25.   End If
  26. Else
  27. End If
Aug 10 '08 #2
NeoPa
32,577 Recognized Expert Moderator MVP
It's not clear what you're trying to achieve, but if you look at lines #10 through #14 (Do Until ... Loop) you will see that they assign values to a couple of items which are neither explained nor referred to elsewhere.

As the first thing you do after assigning them once is to assign them again with (presumably) different values, it's clear to see that this loop is not doing anything for you. If these objects are form controls then there will be no time to see them before they disappear again. Only the last record will remain visible. If they are intended to reference fields in a recordset somewhere (they don't) then apart from that they are never written away anyway (No rst.Edit & rst.Update are ever called).

Hopefully these pointers will help you find your problems. I'm afraid your question is otherwise too unclear to help further.
Aug 11 '08 #3

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

Similar topics

8
15684
by: Eric | last post by:
Let me start off by saying I have VB working model which means no help. I have searched MSDN. It seems that I get "Read the help" instead of answers which is totally useless to me. With that said can someone please help me understand why this does not work? Dim x As String Private Sub cmdlogin_Click() Do Until x = "Corey" If txtlogin = "Corey" Then
4
5836
by: .Net Sports | last post by:
I am trying to display records from a recordset after sql statement: <% sqlstr ="SELECT horsename FROM tblhorseentry WHERE trackname = '" & request.querystring("trackname") & "' and racedate = '" & request.querystring("racedate");" Set rs1 = Server.CreateObject("ADODB.Recordset") rs1.Open sqlstr,pConn,3
2
1794
by: MLH | last post by:
Take a look at the code that follows. Line 110 is the beginning of Do-Loop. Regarding line #220, I find that I'm getting Error #3021 (No Current Record) during execution of line #230. It puzzles me as to Why? I thought if I was on last valid record of RecSet when line #220 executes, I would be sent to process lines after line #400. Am I wrong about that? ==> BEGIN CODE SNIPPET <=== 110 Do Until RecSet.EOF StartAnew:
6
1655
by: jcrouse | last post by:
I am having problems with a Label_Paint event causing a continuous loop. Here is an explanation of the code. I right click on a label and a context menu pops up. I then select a menu item named "cmLSolidColor". Here is its code:
15
51856
by: shannon | last post by:
Hello, I am wondering if a Do until loop can be used in Javascript. I have an array and want to fill the array 10 times with the users details until it reaches 10 or if they press cancel. I'm using window.prompt to get user info. Any suggestions. Do { //ask user to input their details } while (myairline !=10);
3
4946
by: abitlikehomer | last post by:
Hi i am writing a bit of code so that the date and time of a booking can not be booked twice but i am getting an error message saying "loop without do". Any suggestions? setflag = False Do Until EOF(1) Or setflag = True If customer.bookingdate <> txtdate Then GoTo loopend If txttimefrom >= customer.timefrom And txttimefrom < customer.timeto Then setflag = True Else ' 'potentially ok'
4
143999
by: Madhavi | last post by:
Hi Is there any Do Until Loop in C# Maadhavi
3
11875
by: SyGC | last post by:
Hi People, Im trying to do a simple Loop where by an IP address is pinged (Using My.computer.network.ping) and the results, true or false, are used to invoke another line of code. Basically if the IP is pingable (true) image A is displayed if it is not (false) then image B is. The code i am using is as follows Dim IPAddress As String = "192.168.1.122"
5
9289
by: dbrother | last post by:
Access 2003 Win XP Pro SP3 Using SQL /ADO Recordsets in a Do Loop Hello, I'm using a random number generator based on an integer input from a user from a form that will get X number of random records from an external Oracle source using a SQL statement. The SQL statement works as expected when the loop code is commented out, but I receive an error "SQL command not properly ended" when the loop is active. Do Until intLoop = UserNum ...
0
9628
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10289
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8952
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5367
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.