Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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





  #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
  #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





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





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