Problem with Cancel 2 (> Arvin Meyer)

S

Stefan

Hi,

(See earlier post on june, 25th)

I put the code in the form_beforeupdate and the old data reappear, no problem.

But how can I change the data when I push an other button. I putted a
button on the subform to save the record but the old data keeps coming.

Can I re-direct the event-procedure via VBA??

Stefan
 
A

Arvin Meyer [MVP]

You're at cross purposes with yourself.

The only way you can both save and discard data is to hold it twice. You
will need 2 tables with the exact same structure for each form and subform.
Bind the 2nd table to the form, instead of the first. When you open your
form/subform, call only the 1 main and multiple subform records. Do your
editing. Push a save button which will delete the matching data in the main
table, and write the data from the form/2nd table to the first (main) table.
It is fairly complex.

Another way to handle it is not to use bound forms. However, unbound forms
only allow 1 record in the subform, unless you buy a 3rd party grid control.

Last, and this may be the easiest method in your case, is to add a check box
or toggle button to the main form. Check it and conditionally apply your
code in the BeforeUpdate event of the subform. Something like (aircode):

Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Parent.chkSave = True Then
Exit Sub
Else
Me.Undo
End If
End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
A

Arvin Meyer [MVP]

That's 2 tables each for the form and subform. It's the method I use even
though it's a lot more work. That allows closing a session without making
the final decisions, so if a session drops (we use Terminal Servers for many
applications) not a byte of data is ever lost. OTOH, the simplest method is
the last one, and without experience in dealing with recordsets, I suggest
you try that one first.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
S

Stefan

You're probably right.
But maybe there's another solution based on yours.

If I press the 'save' button it has automatically the focus.
Has Access a function that can determine which object has the focus at that
moment ??

The code could then be something like this

Sub Form_BeforeUpdate(Cancel As Integer)
If 'here the test savebutton has focus' Then
Exit Sub
Else
Me.Undo
End If
End Sub


Stefan
 
S

Stefan

I think I got it.

By the way, determine the focus (screen.activecontrol) doesn't work. At that
moment the textbox has still the focus

I declare a variable in the main module so it keeps his value through all
the procedures. If I click the 'change'button the variable gets value 0, as
soon if I click the 'save'button I put it on 1.
Now I can test this variable in the beforeupdate procedure.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If ok <> 1 Then
Cancel = True
Me.Form.Undo
Cancel = False
End If
ok = 0
End Sub

Private Sub buttonsave_Click()
ok = 1
SendKeys "{F9}"
End Sub


Thanks for helping me think.
Stefan
 
Top