Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 5th, 2007, 10:56 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default UpDate Records on a Form

Hi

I have a query QConfirm which populates a Form
The Query is filtered Date to Date and QuoteControl must = True

The Controls in the query are

Date: Quote: ConfirmedOrder
Quote and ConfirmedOrder are Boolean (True of False)

When Order initially raised Quote is True ConfirmedOrder is False
I wish to automatically change

Quote to False
Confirmed True

When I run the code below the error comes up as

"Loop Without Do"

I think the SQL Logic is okay but I am either using the wrong technique to cycle thru the records

Or the SQL is in the wrong place in the procedure
Help Would Be appreciated



Private Sub CmdConfirmOrders_Click()
On Error GoTo Err_CmdConfirmOrders_Click

Dim rstTemp As DAO.Recordset
Dim RecCount As Integer

  Set rstTemp = CurrentDb.OpenRecordset( _
  "SELECT Quote,ConfirmedOrder FROM QConfirm")

  'Move to last record to get the record count
  rstTemp.MoveLast
  RecCount = rstTemp.RecordCount

 'Start the loop
 Loop Until RecCount = 0

    RecCount = rstTemp.RecordCount - 1

    rstTemp.MoveFirst
    If Quote = True And ConfirmedOrder = False Then
    Quote = False And ConfirmedOrder = True
 Loop

 'requery the form
 Me.Requery


 'disable the Cmd Button to avoid an error when no records exist in the Query
Me.CmdConfirmOrders.Enabled = False

MsgBox "All Records have been successfully Updated", vbOKOnly
rstTemp.Close




Exit_CmdConfirmOrders_Click:
    Exit Sub

Err_CmdConfirmOrders_Click:
    MsgBox Err.Description
    Resume Exit_CmdConfirmOrders_Click

End Sub





Reply With Quote
  #2 (permalink)  
Old September 7th, 2007, 12:34 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry for the delay in the reply. Here is the error:

This:
'Start the loop
 Loop Until RecCount = 0

    RecCount = rstTemp.RecordCount - 1

    rstTemp.MoveFirst
    If Quote = True And ConfirmedOrder = False Then
    Quote = False And ConfirmedOrder = True
 Loop

Should be this:
'Start the loop
Do Until RecCount = 0
    RecCount = rstTemp.RecordCount - 1
    rstTemp.MoveFirst
    If Quote = True And ConfirmedOrder = False Then
       Quote = False And ConfirmedOrder = True
    End If
Loop

This doesn't look right, though. If you start this loop, you are only acting on the first record in the recordset, time after time, until you decrement the RecCount variable.

Perhaps you mean this:
'Start the loop
rstTemp.MoveFirst 'moved
Do Until RecCount = 0
    RecCount = rstTemp.RecordCount - 1
    If Quote = True And ConfirmedOrder = False Then
       Quote = False And ConfirmedOrder = True
    End If
    rstTemp.MoveNext 'added
Loop

I am not sure if you can act on a DAO recordset as you do in the If Then conditional, but you wouldn't accomplish anything in ADO this way.

Did any of that help?

mmcdonal
Reply With Quote
  #3 (permalink)  
Old September 8th, 2007, 04:21 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mmcdonal
Hi

This post is linked to the "Using SQL within VBA which was my second attempt at SQL within VBA to solve the problem of changing Quote to No and Making Firm Order Yes

I have one or two other things to try and when the problem is solved I will have increased my understanding of how to construct SQL correctly for use in VBA editor

I think that when the IF THEN statement is code which is attached to a Cmd button on a FORM it does work. I have yet to try it using a DO LOOP circumstance so I hope it still works


Thank you for both yours and other contributors assistance

Man Friday



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Records bspeck Dreamweaver (all versions) 5 October 5th, 2004 03:05 PM
update multiple records mateenmohd Classic ASP Basics 4 June 28th, 2004 03:38 AM
How Can I Update Multiple Records Lucy SQL Server ASP 3 March 18th, 2004 03:19 PM
UPDATE RECORDS!!! a_pathak BOOK: Beginning ASP 3.0 1 March 3rd, 2004 04:00 AM
Help! Cannot update records mcalder Classic ASP Databases 6 August 14th, 2003 01:54 PM



All times are GMT -4. The time now is 01:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.