473,662 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Doing a do while not rst.eof loop not passing on else statement why?

82 New Member
guys .... am already restructuring my codes as am doing a loop after it says that .eof = true if goes directly to endif ... not passing thru else, any idea why?

Expand|Select|Wrap|Line Numbers
  1. Set db = CurrentDb
  2. Set rst = db.OpenRecordset("documentLog", dbOpenDynaset)
  3.  
  4. rst.MoveFirst
  5.  
  6. If Not rst.EOF Then
  7.     Do While Not rst.EOF
  8.         If rst!docLogNo = Me.txtDocLogNo.Value Then
  9.             Me.txtBadgeNo = rst!badgeNo
  10.             Me.txtFullName = rst!fullName
  11.             Me.txtWBRef = rst!wayBillRef
  12.             Me.txtLocation = rst!location
  13.             Me.txtFileCode = rst!fileCode
  14.             Me.txtDocType = rst!docNo
  15.             Me.txtDocNo = rst!docType
  16.             Me.txtDocTitle = rst!docTitle
  17.             Me.txtAssetNo = rst!assetNo
  18.             Me.txtEquipType = rst!equipType
  19.             Me.txtEquipModel = rst!equipModel
  20.             Me.txtAssetOwner = rst!assetOwner
  21.             Me.cmbTakeOutDay = rst!takeOutDay
  22.             Me.cmbTakeOutMonth = rst!takeOutMonth
  23.             Me.txtTakeOutYear = rst!takeOutYear
  24.             Me.cmbReturnedDay = rst!returnedDay
  25.             Me.cmbReturnedMonth = rst!returnedMonth
  26.             Me.txtReturnedYear = rst!returnedYear
  27.  
  28.             Exit Do
  29.         End If
  30.         rst.MoveNext
  31.     Loop
  32. Else
  33.     MsgBox "Record not Found!"
  34.  
  35.     Me.txtDocLogNo.Value = ""
  36.     Me.txtBadgeNo.Value = ""
  37.     Me.txtFullName.Value = ""
  38.     Me.txtWBRef.Value = ""
  39.     Me.txtLocation.Value = ""
  40.     Me.txtFileCode.Value = ""
  41.     Me.txtDocType.Value = ""
  42.     Me.txtDocNo.Value = ""
  43.     Me.txtDocTitle.Value = ""
  44.     Me.txtAssetNo.Value = ""
  45.     Me.txtEquipType.Value = ""
  46.     Me.txtEquipModel.Value = ""
  47.     Me.txtAssetOwner.Value = ""
  48.     Me.cmbTakeOutDay.Value = ""
  49.     Me.cmbTakeOutMonth.Value = ""
  50.     Me.txtTakeOutYear.Value = ""
  51.     Me.cmbReturnedDay.Value = ""
  52.     Me.cmbReturnedMonth.Value = ""
  53.     Me.txtReturnedYear.Value = ""
  54.  
  55.     Me.txtDocLogNo.SetFocus
  56. End If
  57.  
  58. rst.Close
  59.  
  60. Set rst = Nothing
  61. Set db = Nothing
Apr 9 '13 #1
12 2794
MikeTheBike
639 Recognized Expert Contributor
Hi

My initial thought here is that rst.EOF is actually False, but none ot the returned records match the txtDocLogNo value. This would then appear to do absolutly nothing !!

??


MTB
Apr 9 '13 #2
deanvilar
82 New Member
hi Mike, yes initially it's false ... my input in txtDocLogNo <> with rst!docLogNo so when .eof = true it must tell the user that record is not found.
Apr 9 '13 #3
Seth Schrock
2,965 Recognized Expert Specialist
I'm a little confused about your question. Can you explain the path you expect the code to take using line numbers from above? It sounds like you are expecting it to do the Do While loop starting on line 7 and then take the Else path on line 32 based on your title and question.

Also, are there multiple records where rst!docLogNo = Me.txtDocLogNo. Value? If not, there is a much better way to do this.
Apr 9 '13 #4
deanvilar
82 New Member
Hello master seth, to give a clear picture on this ... user will be searching onto me.txtDocLogNo, do while not rst.eof will go thru the records to find rst!docLogNo = me.txtDocLogNo( entry), the log number is not existing it must pass thru line 32 to tell that record not found .. I hope you understand my explanation =)
Apr 9 '13 #5
Seth Schrock
2,965 Recognized Expert Specialist
Once the test in line 6 is executed, it will either go to the True path or the False path (the Else). If it goes to the true path (there are records), then it won't go to the False side as the condition (Not rst.EOF) was already tested as true. So you need to reorder where you have your IF/Then statements to test for things as they will occur.
Apr 9 '13 #6
deanvilar
82 New Member
understood the explanation sir seth, I have tried re-organizing my if/then statements ... till now I can't figure out how to verify that record not found uuuuuuuuuufffff ...
Apr 9 '13 #7
Seth Schrock
2,965 Recognized Expert Specialist
A much better way to do this would be to setup a query that has the criteria equivalent to rst!docLogNo = Me.txtDocLogNo. Value. This is much more efficient that looping through every single record, which is what your code will do. If/when you get thousands of records, this will take a lot of time and the database can't benefit from any indexes. Try something like this (this assumes docLogNo is a number):
Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Dim strQuery As String
  3. Dim rst As DAO.Recordset
  4.  
  5. Set db = CurrentDb
  6. strQuery = "SELECT * FROM documentlog WHERE docLogNo = " & Me.txtDocLogNo
  7. set rst = db.OpenRecordset(strQuery, dbOpenDynaset)
  8.  
  9. If rst.RecordCount > 0 Then
  10.     'Do your code here
  11. Else
  12.     'Do your false code here
  13. End If
  14.  
  15. rst.Close
  16.  
  17. Set rst = Nothing
  18. Set db = Nothing
Now if only one record can match the criteria in the query, then you don't need a loop.
Apr 9 '13 #8
deanvilar
82 New Member
sir seth, yes docLogNo is number but I made it as docLogNo as text in table .... yes .. only 1 records can match the criteria ...
Apr 9 '13 #9
deanvilar
82 New Member
sir error --> DATA TYPE MISMATCH IN CRITERIA EXPRESSION in line
Expand|Select|Wrap|Line Numbers
  1. Set rst = db.OpenRecordset(strQuery, dbOpenDynaset)
Apr 9 '13 #10

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

Similar topics

18
3059
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
2
1798
by: paul | last post by:
Hi all, I've been handed some code and, unless I've got the numbering of parentheses wrong, one of the functions has a curious if-else statement. The thing compiles but is it right? I know the code contains non-standard C++, but its only the if statement I'm after. It seems to go: if (condition){
16
5444
by: bitong | last post by:
Just cant figure out how to formulate the correct syntax..I can do it in looping statement but my professor said that use only the simple if-else statement. The problem goes like this..Write a program that will determine if the number that you entered is either odd or even number.. I tried writing this code.. #include<stdio.h> main() { int nos; clrscr(); printf("Enter number:");
2
4080
by: juan-manuel.behrendt | last post by:
Hello together, I wrote a script for the engineering software abaqus/CAE. It worked well until I implemented a selection in order to variate the variable "lGwU" through an if elif, else statement. I am going to post the first 82 lines of the script, since the error message points at line 80: from abaqusConstants import * from abaqus import *
5
8182
by: clear1140 | last post by:
Good day!! I was wondering if it is possible to put an if else statement inside a where clause of an sql statement... you see i would like my update statement to do this: update trial_clear set num = @count2 /* @count2 is a integer passed*/ where if (select top 1 def from trial_clear where num is NULL) is NULL def is NULL else
2
8437
by: MicaK | last post by:
Good Morning, I am new to this forum, and extremely new to VBA, so there may be a very simple explanation to this. I also apologize if I am giving you and excessive amount of detail. I have a table, tblAdmissions. One of the columns is for Certification and was set up as a lookup field that allows multiple values to be selected. In my form, the label for this field is called lblCertification, and the combo box is called cboCertification. ...
4
2789
by: maveri4201 | last post by:
I have written a php script (test3.php), which I attached as a text file. Its includes are also attached as text files. I'm trying to run the script here: http://www.wondergy.com/phptestbed/test3.php The problem I'm having is the frustrating Unexpected $end. Yes, I know that it usually means something isn't being closed correctly. The problem is, I can't figure out what. To make the problem stranger, I can get it to parse when I break it up...
6
2275
by: DanicaDear | last post by:
I have this update strSQL that is working great, but I'd like to make it smarter in hopes of preventing input errors. Here is my working code: Else Me.txtScan_Box_Num = Me.txtScanCapture 'Box exists. 'Assign box to current customer, and set box return date=now Dim strSQL As String strSQL = "UPDATE tblBOX SET...
3
1577
Siddarth777
by: Siddarth777 | last post by:
here am sending u the code of the simple linked list implementation in C language when we go to the append function definition,in the if statement a new node is being created if address of the structure is NULL then after the creation the address is being assigned to the temp. there is nothing weird in that the weird part comes in else statement if you find a node already created you goto the last node and then you append it by adding a...
2
1480
by: Robert Ingles | last post by:
I apologize for my current lack of knowledge and hope that someone will be kind enough to give me some additional help.I posted a question regarding "Record does not exist, open add record form". I have managed (with the help of ADezii) to have the add new user form open up if there is no matching userID record in the TBLUser (BTW Userid is text) however even if the user does exist the add new user form opens up. I think I need an "Else"...
0
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
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
8768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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
7368
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
6186
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
5655
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();...
2
1754
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.