Page 14 of 16 FirstFirst ... 45678910111213141516 LastLast
Results 196 to 210 of 233
  1. #196
    Heathey94 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Location
    United Kingdom
    Posts
    282
    In both instances, we're looking at the ID and creating an error message if it's already on there, but with DocumentPK (and LiberiID and LoginID), we're "undo"-ing it if the ID is already on there. Now I think about it, however, maybe Cancel would be better. Am I right in thinking Undo wipes everything on the screen, whereas Cancel undoes the last action?

  2. #197
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Yes, I told you to remove all those undo's, they are horrible. And no, cancel stops the action from happening (when Access gives you that option), doesn't undo anything.

    You are getting lost in all of this back and forth. Go back to what you want to happen - check if it has been entered before (the called subroutine) and if it has then clear it out give them an error message.

  3. #198
    Heathey94 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Location
    United Kingdom
    Posts
    282
    Did you? I'm losing track. ok, Cancel is probably what I want to use then, but I still haven't had to define it anywhere else, so have nothing to reference.

  4. #199
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Sorry but it is a reserved Access parameter! You have to work around it by using other methods. Yes it would be nice to have, you will see complaints all over the internet about this, even setting focus doesn't work in this situation so it is hard to do. All you can do is clear it out (without using undo!) and the user will have to go back to it themselves.

  5. #200
    Heathey94 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Location
    United Kingdom
    Posts
    282
    What if you're on a record and try to change the ID to another ID, but that is already in the system? Then it needs to revert back to how it was (which is why undo was working)

  6. #201
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Except that undo wipes out everything the user has entered up til then. If you need to revert then use name.oldvalue.

  7. #202
    Heathey94 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Location
    United Kingdom
    Posts
    282
    "Invalid use of property"?
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If ChangeBehaviour(Me.AssessmentID, Me.BehaviourID, Me.ResponseID, Cancel) = True Then
    BehaviourID.OldValue
    End If
    End Sub

  8. #203
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    equal sign

  9. #204
    Heathey94 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Location
    United Kingdom
    Posts
    282
    BehaviourID=BehaviourID.oldvalue?

  10. #205
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Perfect!

    (too short!)

  11. #206
    Heathey94 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Location
    United Kingdom
    Posts
    282
    That worked! However... for BehaviourID, if you select a behaviour which has already been entered, it creates an endless loop with the message box continuously appearing... this is my code:
    On the Module:
    Code:
    Public Function ChangeBehaviour(AssessmentID, BehaviourID, ResponseID)
    Dim BehID As Long
     On Error Resume Next
     BehID = DLookup("BehaviourID", "TblAssessmentDetails", "BehaviourID=" & BehaviourID & " AND AssessmentID=" & AssessmentID & " AND ResponseID<>" & ResponseID)
     If BehID > 0 Then
     MsgBox "This behaviour has already been selected on this assessment."
     ChangeBehaviour(AssessmentID, BehaviourID, ResponseID) = True
     Else
     ChangeBehaviour(AssessmentID, BehaviourID, ResponseID) = False
     End If
    End Function
    On the Form:
    Code:
    Private Sub BehaviourID_AfterUpdate()
    If ChangeBehaviour(Me.AssessmentID, Me.BehaviourID, Me.ResponseID) = True Then
    BehaviourID = BehaviourID.OldValue
    End If
    End Sub
    
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If ChangeBehaviour(Me.AssessmentID, Me.BehaviourID, Me.ResponseID) = True Then
    BehaviourID = BehaviourID.OldValue
    End If
    End Sub

  12. #207
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    That is because you are doing the check both before and after. The before is not necessary, they haven't entered anything yet.

    Also, in the module, remove the parameters in the code: ChangeBehaviour=True/False

  13. #208
    Heathey94 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Location
    United Kingdom
    Posts
    282
    OK, we're getting there! Now its fine if you change a row with a behaviour already selected to a different behaviour which already appears on the list, but doesn't like it if you choose a behaviour which has already been selected from the new row, so I think it needs something, like this, what do you think?
    Code:
    If ChangeBehaviour(Me.AssessmentID, Me.BehaviourID, Me.ResponseID) = True Then
        If IsNull(BehaviourID.oldvalue) Then 
            Me.Undo
            On Error Resume Next
            DoCmd.RunSQL "DELETE * FROM TblAssessmentDetails WHERE ResponseID=" & Me!ResponseID & ";"
            Me.Requery
       Else
            BehaviourID = BehaviourID.OldValue
       End If
    End If

  14. #209
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    1 - REMOVE undo from your damn vocabulary! What is it that you are so attached to it? If you want to clear out a field then set it to "" or null, but stop wiping out everything the user has entered! Haven't you experienced websites like this - one wrong entry and everything gets cleared out? And doesn't it irritate you?
    2 - If this code is in the FORM's after update then you need to delete the record, but until that point the record is still in memory and hasn't been added to the table yet.

    So, remove all lines, make the first part of the IF the same as the second - just clear out the entered value.

  15. #210
    Heathey94 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Location
    United Kingdom
    Posts
    282
    That was because I'd copied it from the DeleteRow button... so should that be changed to null too?

    And the reason I'm going down this route in the first place is because it didn't like it being null, so surely setting it to null won't work?

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

Similar Threads

  1. Replies: 13
    Last Post: 04-21-2016, 03:33 AM
  2. Macro to Open Form Triggers Exclusive Access Message
    By snakatsu in forum Database Design
    Replies: 5
    Last Post: 11-10-2015, 10:46 PM
  3. Replies: 6
    Last Post: 09-30-2015, 03:14 PM
  4. Multiple options based on a tree structure...
    By blue22 in forum Database Design
    Replies: 3
    Last Post: 01-09-2014, 05:58 AM
  5. Replies: 1
    Last Post: 08-01-2011, 04:17 PM

Tags for this Thread

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