Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Triple Crown (Yes, No, Cancel)

Status
Not open for further replies.

SilverBean

Programmer
May 23, 2001
44
US
My scenario is that I have a form which is has button Done which the user is clicking to signal they have either made an Edit or Add - I do know which.

I would like for my Form_BeforeUpdate routine to run so the click event just does a Me.Refresh. I have also tried a variety of other "things" like DataEntry=False, Requery, Me.Dirty=False - all have given me the same results. The BeforeUpdate fires but I'm observing an undesired side effect.

Furthermore I'd like my BeforeUpdate event to do a Yes, No, Cancel. Yes would save, No - discard, Cancel allow further edits. I viewed countless posts here - not sure if others are trying to do the triple in the Before Update event, some seem to have the Undo separate. This is key, the user is under the perception that they can have a Yes, No, Cancel - and why can't they?

I really want everything in the BeforeUpdate event - for obvious reasons.

The PROBLEM is when I'm doing an Add with no records present, and then do a Done, VBA seems to have a very hard time with things. In general I think that having the undo in my BeforeUpdate event is causing problems. For example:

Private cmdDone_Click

Me.Refresh
End Sub

Private Sub Form_BeforeUpdate(Cancel as Integer)
answer = MsgBox("Yes - saves, No -discards, Cancel - continue making changes", vbYesNoCancel, "Confirm changes")
Select case answer
case vbYes
Cancel = False
case vbNo
Cancel = True
Me.Undo
case vbCancel
Cancel = True
End Select
End Sub

The Done click gives me a run time error. Which I could trap for but that just seems sloppy. Just for laughs I do the add and then I enter some data and do a manual refresh(Records, Refresh) and the update fires and works perfectly. I guess Records Refresh <> Me.Refresh.

Again this only errors during an Add with no records - which reasons not disclosed here is a concern. Once again just trying to add a little Cancel button here, this DB has just been chugging along quite well.

I stumbled across a bug on Form Close not saving data seemed maybe like something similair(i.e., a bug :) ), but seriously I'm not doing a form close here.

I've pretty much convinced myself that undo on a control does not work(i.e., sometextField.Undo - doesn't do anything). I've got Access 2002, Dynasets, and this is just totally useless. I even tried .Value = .OldValue does not seem to work still same error. This would be a viable solution if unlike the vbCancel (i.e. Cancel = True) if I could just erase the values in the controls I could programmatically prevent the user from doing anything else. I think there in lies the problem is that I'm trying to yank the data away while VB is trying to do an update.

Any help would be appreciated.


 
Yes, why shouldn't they have a yes no cancel?

In your "done" button, use:

[tt]if me.dirty then
<preferred method of saving>
' and perhaps?
else
msgbox "there's nothing to save..."
end if[/tt]

These problems you're having, in spite of all the text, I'm finding it a bit hard to find out what the real problem is, you haven't quoted any errormessages, you're just saying there are errors and behaviour not to your liking.

Here's a link on the bug/flaw you're mentioning, which also has a bit of information on different ways of saving Losing data when you close a form

In stead of just asking the users if they wan't to save in the before update, have you considered doing some testing and validation there?

For instance, if me.newrecord is true, then you're trying to save a new record. If isnull(<your controls being required>) - give the users a message that they can't save without entering data...

If the record is previously saved, the Me.Undo will put the record back to the condition it had at the last save. If you by "discard" mean to delete both the changes to the record and the record, then delete the record. Just clearing the controls for a record that's alredy saved, will probably give other errors.

I haven't had much success in the control.undo either.

For more assistance, please try to be a bit more precise in what code gives which error (and quote the full errormsg)...

BTW - how is your progress on thread705-808551?

Roy-Vidar
 
Yes, I knew I forgot a piece above or should've been more explicit - was on my way out the door.

Problem is when a User does a click on Done, and then responds "No" to the MsgBox in BeforeUpdate. This only happens when there are initially no records which is something I need to be able to handle more gracefully.

Depending on which permutation of saving that I did, which I didn't record depends on the specific Runtime error that VB would respond with.

A current thought was that if I turned the filteron and set it to something meaninful(particularly the record just being added) that might force the update in Done. This did happen, but I am getting a run time error unable to save record at this time at the FilterOn = true line. I'm not surprised because VB was unable to save because the BeforeUpdate Canceled or Undo-ed(did).

In the observation which I recorded above. I was getting another run time error at the Me.Refresh line about "not having an expression that has an invalid reference to the property |." - yea it has the straight bar thing at the end for some reason like something is really confused but at least its punctuated correctly.

You did give me a little piece to gnaw on though. The thing about the Undo going back to previously saved data, well in my case there is no previously saved data because its an add - your making me think about it differently. Also the Delete thing like that also. Two thing for me to consider.
 
No none of the ideas above panned out still no luck.

I'd love to put anything in cmdDone_click and I have tried just about everything including

Me.Dirty = False
turning filter on
Me.Refresh
DoCmd.RunCommand Refresh thing
just to a name of a few of the most likely to succeed idea.
About the only things I haven't tried is moving to a new record seems odd because I know full well there isn't any AND DoCmd.MenuItem which I hate.

My problem isn't in saving its in undoing the save. I want to put as much processing in BeforeUpdate so in case a user sneaks out so putting a decision in Done is really something I'd like to avoid.

Also Roy-Vidar I followed on that previous thread in that area, thanks for all your help. That issue is long gone now.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top