473,508 Members | 2,283 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 2778
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
deanvilar
82 New Member
now it's ok sir seth ... i changed something in
Expand|Select|Wrap|Line Numbers
  1. strQuery = "SELECT * FROM documentLog WHERE docLogNo =  '" & Me.txtDocLogNo & "'"
now its working just as smooth as silk! thanks to you sir!
Apr 9 '13 #11
Seth Schrock
2,965 Recognized Expert Specialist
Yep. That is what needed to change so that it would handle the text type. Glad you got it to work.
Apr 9 '13 #12
deanvilar
82 New Member
thank you for your help as always sir seth .. i really appreciate it .. thank you
Apr 9 '13 #13

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

Similar topics

18
3044
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
2
1783
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...
16
5427
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...
2
4071
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...
5
8168
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...
2
8417
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...
4
2784
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...
6
2258
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 =...
3
1575
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...
2
1474
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...
0
7224
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
7120
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...
1
7039
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
7494
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
4706
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...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
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 ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
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...

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.