UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Me.Dirty = False not working!    
 
   
kbrewster
post Jun 7 2006, 11:02 AM
Post#1


UtterAccess VIP
Posts: 4,504
Joined: 18-August 03
From: NH


I have the following code on my form...
CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.Dirty = True Then
    Select Case MsgBox("Want to save or not?", vbYesNo, "Save Changes?")
    Case vbYes
        Me.Dirty = False
            If IsNull(Me.POEnteredBy) Then
                Me.POEnteredBy = Forms!frmHidden!txtFullName
                Me.POEnteredDate = Now
            End If
    Case vbNo
        Me.Undo
    End Select
    End If
End Sub

I keep getting Run-time error 2115. What am I doing wrong?
Go to the top of the page
 
Willem
post Jun 7 2006, 11:05 AM
Post#2



Posts: 467
Joined: 18-April 06
From: Amersfoort, The Netherlands


Me.POEnteredDate = Now
hould be
Me.POEnteredDate = Now() ?
Go to the top of the page
 
kbrewster
post Jun 7 2006, 11:07 AM
Post#3


UtterAccess VIP
Posts: 4,504
Joined: 18-August 03
From: NH


Well that was not the problem...
When I debug it goes to the line
Me.Dirty = False
Go to the top of the page
 
niesz
post Jun 7 2006, 11:12 AM
Post#4


Utter A-fishin'-ado
Posts: 17,958
Joined: 1-August 05
From: Cincinnati, Ohio, USA . . . ><((((°>


You're trying to save the record in the Before Update event. It cannot do this in this event. I think you just want to cancel the update if they say NO to the save and just let the rest of the event continue if they answer YES.
Go to the top of the page
 
kbrewster
post Jun 7 2006, 11:16 AM
Post#5


UtterAccess VIP
Posts: 4,504
Joined: 18-August 03
From: NH


Huh? What line in the code says I am saving it? All I am trying to do is update two controls if they say yes. I want this code to run no matter what the user does...closes the form, clicks New to add a new record, or anything else. What event could I run this on?
Go to the top of the page
 
niesz
post Jun 7 2006, 11:19 AM
Post#6


Utter A-fishin'-ado
Posts: 17,958
Joined: 1-August 05
From: Cincinnati, Ohio, USA . . . ><((((°>


Setting Me.Dirty = False saves the record. Give me a second and I'll see ifI can put together a sample. You just want to confirm the save, correct?
Go to the top of the page
 
kbrewster
post Jun 7 2006, 11:20 AM
Post#7


UtterAccess VIP
Posts: 4,504
Joined: 18-August 03
From: NH


Yes I just want to confirm the save and if they say no, undo all changes. Thanks!
Go to the top of the page
 
niesz
post Jun 7 2006, 11:29 AM
Post#8


Utter A-fishin'-ado
Posts: 17,958
Joined: 1-August 05
From: Cincinnati, Ohio, USA . . . ><((((°>


Try this:
CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    If MsgBox("Want to save or not?", vbYesNo, "Save Changes?") = vbYes Then
        If IsNull(Me.POEnteredBy) Then
            Me.POEnteredBy = Forms!frmHidden!txtfullname
            Me.POEnteredDate = Now
        End If
    Else
        Me.Undo
        Cancel = True
    End If
    
End Sub
Go to the top of the page
 
kbrewster
post Jun 7 2006, 11:32 AM
Post#9


UtterAccess VIP
Posts: 4,504
Joined: 18-August 03
From: NH


Awesome...that works great!
Thanks! frown.gif
Go to the top of the page
 
niesz
post Jun 7 2006, 11:33 AM
Post#10


Utter A-fishin'-ado
Posts: 17,958
Joined: 1-August 05
From: Cincinnati, Ohio, USA . . . ><((((°>


Glad to help.
Go to the top of the page
 
niesz
post Jun 7 2006, 11:37 AM
Post#11


Utter A-fishin'-ado
Posts: 17,958
Joined: 1-August 05
From: Cincinnati, Ohio, USA . . . ><((((°>


P.S. To check for empty fields, instead of using:
If IsNull(YourFieldOrControl) Then
...
..use..
If Nz(YourFieldOrControl) = "" Then
...
That way it will check for Nulls and Empty Strings. frown.gif
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    23rd May 2019 - 08:35 AM