Results 1 to 4 of 4
  1. #1
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128

    Question Can't get these Two Codes to Mesh! Will work solo...

    I have a code under one button that copies the record and pastes it so that a new date can be used with the old values:

    Private Sub chkOldValues_Click()

    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.RunCommand acCmdRecordsGoToNew
    DoCmd.RunCommand acCmdPasteAppend

    Me.Days.Value = Me.txtDate.Value

    [Forms]![frmGenSum]![UserID].Enabled = False

    Me.chkOldValues.Value = False

    End Sub


    I also have a code that checks the date and userID to ensure that the same date (with the specified userID) have not been used before:

    If chkOldValues.Value = True Then
    Exit Sub
    End If

    Dim rs As Object

    Set rs = CurrentDb.OpenRecordset("tblDailyReport")

    If rs.EOF And rs.BOF Then
    'Do nothing
    End If

    Do While Not rs.EOF
    If rs!Days = [Forms]![frmGenSum].Days And rs!UserID = [Forms]![frmGenSum].UserID Then
    MsgBox "This User ID has already used this date. Use the Previous Dates box to go to a date."
    Exit Do
    End If
    Loop



    Set rs = Nothing

    End Sub


    However, if I have both codes in the form, then only the copy record piece works. If I try to check a date, the database hangs. At the moment, only one or the other will work.

    Any ideas on what is happening and how to fix it? I am not great at RecordSets, I happened across this code and modified it for my own use, but now it just won't play well with the other code! Thanks for all the help.

  2. #2
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Er, it's not hanging but in an infinite loop! You are missing an rs.MoveNext statement immediately before the Loop.

  3. #3
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    An afterword.

    Be careful about nulls in the fields on your form.

  4. #4
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128
    Quote Originally Posted by Rod View Post
    Er, it's not hanging but in an infinite loop! You are missing an rs.MoveNext statement immediately before the Loop.
    Works like a charm now! Thanks.

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

Similar Threads

  1. Queries and codes
    By alliandrina in forum Queries
    Replies: 2
    Last Post: 05-03-2012, 05:53 PM
  2. Consolidation codes from different table.
    By suverman in forum Queries
    Replies: 3
    Last Post: 05-13-2011, 10:39 AM
  3. Zip Codes
    By Laurie B. in forum Access
    Replies: 6
    Last Post: 02-25-2011, 02:38 PM
  4. Visual Mapping Using Zip Codes?
    By kalisti in forum Reports
    Replies: 1
    Last Post: 01-03-2011, 07:26 PM
  5. basic query codes
    By joms222 in forum Queries
    Replies: 1
    Last Post: 03-20-2009, 11:31 AM

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