Results 1 to 6 of 6
  1. #1
    dalet is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2009
    Posts
    7

    Access to SQL error

    I'm converting an Access database to SQL and can't get this Module to run. It won't go past the Loop and if I take out Loop I get an "End With with With" error.

    Function ClearPrintBook()
    'Make all Printing set to = False This first part works!
    Dim rst As Recordset
    Dim db As Database
    Set db = CurrentDb
    Set rst = db.OpenRecordset("Sheet1", dbOpenDynaset, dbSeeChanges)
    With rst
    Do While Not .EOF
    .Edit
    !Printed = False
    .Update
    .MoveNext
    Loop
    End With


    rst.Close
    Set rst = Nothing
    db.Close
    Set db = Nothing
    End Function

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Code:
     
    Function ClearPrintBook()
    'Make all Printing set to = False This first part works!
    Dim rst As DAO.Recordset
    Set rst = CurrentDb.OpenRecordset("Sheet1", dbOpenDynaset, dbSeeChanges)
    
    If Not rst.EOF And Not rst.BOF Then
      Do While rst.EOF
         rst.Edit
         rst("Printed") = False
         rst.Update
         rst.MoveNext
      Loop
    
      rst.Close
    End If
    Set rst = Nothing
    End Function
    Or you could simply do

    Code:
     
    DoCmd.SetWarnings False
    DoCmd.RunSQL "Update Sheet1 Set Printed = False"
    DoCmd.SetWarnings True
    David

  3. #3
    dalet is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2009
    Posts
    7
    Thank you very much for the help. Now if I could understand how that fixed my problem I would be a happy man.

  4. #4
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Which option did you go for in the end?

  5. #5
    dalet is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2009
    Posts
    7
    Went with the first one.

  6. #6
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    The major difference in the code, apart from being more asthetic, is the Do While line.

    You had
    Do While Not .EOF

    I changed it to

    Do While Rs.EOF

    In your line you were saying do while not true, which is False and as you were not at the end of file .EOF = False so therefore it went straight to the End With line

    David

Please reply to this thread with any new information or opinions.

Similar Threads

  1. [Error]Access Crashed Issues
    By ckhaos in forum Security
    Replies: 1
    Last Post: 06-23-2009, 02:08 PM
  2. Error excel refresh from access
    By goyal in forum Access
    Replies: 0
    Last Post: 06-10-2009, 10:59 AM
  3. Replies: 0
    Last Post: 05-14-2009, 12:34 AM
  4. Replies: 0
    Last Post: 06-19-2007, 09:45 AM
  5. Replies: 1
    Last Post: 12-09-2005, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums