PC Review


Reply
Thread Tools Rate Thread

comparing 2 values from 2 tables

 
 
Kim
Guest
Posts: n/a
 
      1st Feb 2004
I am trying to compare 2 values from 2 tables.
If the values differs then a message should be displayed.
below is the routine that I created:

Public Sub comparelines()

Dim rst As Recordset
Dim rst1 As Recordset
Dim dbs As Database
Set dbs = CurrentDb()

Set rst = dbs.OpenRecordset("SELECT * FROM tblinvoices
ORDER BY telnr", dbOpenDynaset)
Set rst1 = dbs.OpenRecordset("SELECT * FROM
tbltelephonelines ORDER BY telnr", dbOpenDynaset)

Do
While Not rst1.EOF
If rst!telnr = rst1!telnr Then
rst.MoveNext
rst1.MoveNext
Wend
ElseIf rst!telnr <> rst1!telnr Then
MsgBox (rst!telnr & " " & "cannot be found in the
database")
rst.MoveNext

Loop Until rst.EOF
End if

rst.Close
rst1.Close
db.Close

Set rst1 = Nothing
Set rst = Nothing
Set db = Nothing
End Sub

When compile the routine I get the following error
message:
compile error wend without while.
any help is most appreciated.


 
Reply With Quote
 
 
 
 
Bas Cost Budde
Guest
Posts: n/a
 
      1st Feb 2004
Let me indent your code for you:
> Set dbs = CurrentDb()
>
> Set rst = dbs.OpenRecordset("SELECT * FROM tblinvoices ORDER BY telnr", dbOpenDynaset)
> Set rst1 = dbs.OpenRecordset("SELECT * FROM tbltelephonelines ORDER BY telnr", dbOpenDynaset)
>
> Do
> While Not rst1.EOF
> If rst!telnr = rst1!telnr Then
> rst.MoveNext
> rst1.MoveNext
> Wend
> ElseIf rst!telnr <> rst1!telnr Then
> MsgBox (rst!telnr & " " & "cannot be found in the database")
> rst.MoveNext

?!
> Loop Until rst.EOF
> End if


You cannot nest tests/loops like this. Draw the structure of the code
for yourself in a diagram or so, and code again.


--
Bas Cost Budde

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing tables to locate zero values =?Utf-8?B?U0lUQ0ZhblRO?= Microsoft Access Queries 4 14th Jun 2007 08:54 PM
Comparing values in two columns and displaying missing values in n =?Utf-8?B?Y3BldHRh?= Microsoft Excel Programming 1 2nd Apr 2005 07:18 AM
Graph - comparing values of 2 series while adding an attribute for each compared values Chen G Microsoft Excel Charting 2 1st Nov 2004 08:08 PM
Graph - comparing values of 2 series while adding an attribute for each compared values Chen G Microsoft Excel Misc 1 1st Nov 2004 03:44 AM
Comparing values in same field to return only first unique values =?Utf-8?B?U0Q=?= Microsoft Access Queries 4 27th Oct 2004 09:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:21 PM.