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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create Cancel/undo button 3

Status
Not open for further replies.

amcodah

Programmer
Jul 9, 2003
80
NO
Hi, I'm getting quite used to VBA coding now. But I can't seem to find a built in function for making an undo/cancel button.

Anyone that has solved this problem before?
 
amcodah,

try:

docmd.runCommand accmdUndo

there are lots of useful functions in the docmd.Runcommand feature. Its well worth trying there if you can't find what you need

HTH
Rich

Lead Developer
 
Do be aware, though, that with a bound form, there are ways a user can make "undo" ineffective:
-click on the record selector on the left side of the form
-hit ctrl-s
-use the menu item to save the record

There may be more, but those are the ones that just popped into my head.

If you really need the record to not be saved unless the user explicitly takes an action to save it, you'll have to investigate unbound forms. The short of it is that you'll use VBA to create a recordset for the current record and fill all of the controls with data from that recordset. When the user hits a "save" button, you'll use vba to commit the changes, either with a recordset or by executing a sql statement. If the user moves to another record or closes the form without saving, you'll want to warn the user that doing so will abandon any changes made to the record, and give the opportunity to cancel that action.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Affordable Development, Professionally Done

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Thanks both for you'r feedback. I see what you'r meaning jeremy. I'll try to see if I find a solution to it. As for now the docmd.runCommand accmdUndo works perfect for me :)
 
I have another problem now RichD. If the user hasn't changed or entered anything I get an runerror msg when trying to execute the acCmdUndo command. I need to check if there has been entered anything. Isn't there a easier way to this than checking all variables, ie:

If (gender Or age Or school Or education) Then
DoCmd.RunCommand acCmdUndo
DoCmd.RunCommand acCmdClose
Else
DoCmd.RunCommand acCmdClose
End If
 
Hi amcodah,

Check out the Dirty property of the form. It is true if there are any changes to any controls, so ..

Code:
If Me.Dirty then DoCmd.RunCommand acCmdUndo

.. should do what you want.

Enjoy,
Tony
 
Thanks alot! This forum is really helpful for a newbie in VBA! Keep it up! ;)

/am
 
Is there any method/property that can check if there has been entered values into all REQUIRED fields in a form? IE:


If Not (requiredfield1 Or requiredfield2 Or requiredfield3) Then
MsgBox("Please fill out all fields marked with *", vbOKOnly + vbCritical + vbDefaultButton1, "Required Fields!")
Else
DoCmd.Close acForm, frm_Test, acSaveNo
End If
 
Hi amcodah,

Not that I know of. You have to code that yourself - there are techniques (using the Tag property, for example) which can help you do it in a loop rather than hard coding individual control names, but there's no Form property.

Enjoy,
Tony
 
Okay, I'm trying to hardcode it now. But having real problems with type mismatch etc. Is there anyone that know of a simple solution to this?

I'm basicially trying to check all attributes in one If now IE:

If IsNull(requiredfield1 Or requiredfield2 Or requiredfield3) etc.. wich is causing error of type mismatch.
 
Hi amcodah,

You can't combine conditions like that. You do it like this ..

Code:
If IsNull(requiredfield1) Or IsNull(requiredfield2) Or etc.

Enjoy,
Tony
 
Ok! yes ofcourse, thanks alot for the help tony, you saved me for alot of work ;)
 
you'd want to check for blanks too, plus a slicker way:

if isnull(requirefield1) or requiredfield1 = "" then
msgbox "Please enter a blah!",vbokonly,"Error"
me.requiredfield1.setfocus
exit sub
end if

if isnull(requiredfield2) or requiredfield2 = "" then
...same stuff
end if

this way it says exactly which field is missing data and plops the cursor there for the user.

moving even further on, you can check the data to make sure they've entered values that you consider appropriate: IE make sure it's valid as far as your 'rules' go (between certain values or whatever)....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top