473,403 Members | 2,284 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,403 software developers and data experts.

Do Until Loop Help!

129 100+
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 3141
ADezii
8,834 Expert 8TB
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,556 Expert Mod 16PB
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
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...
4
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 =...
2
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...
6
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...
15
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...
3
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...
4
by: Madhavi | last post by:
Hi Is there any Do Until Loop in C# Maadhavi
3
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...
5
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...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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...

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.