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

Problems Cancelling a opening form. 1

Status
Not open for further replies.

aexley

Technical User
Jul 9, 2001
147
GB
Not sure if this should be in the VB forum but here goes.

I am opening a form, if this form opens onto a new record I need Access to open a message box that requests whether data is transferred to this form or not or the action is cancelled. If the action is cancelled the user is put back to the form they originated from.

The first two parts work fine (after much tweaking), my problem is that when the user tries to cancel I get the following message:

'This action can't be carried out while processing a form or report event'

And then Access opens the form anyway. I have the necessary code in the OnCurrent Event in the target form. I have tried using CancelEvent but I can't get it to work. Any ideas?

Thanks in advance,

aexley

QFTD: "If your washing powder got your whites whiter than white and your colours brighter than ever..why do we need a new one? Whats next nuclear white?"
 
What are you doing to try to cancel the Form_Open event ?

This works fine for what you want as far as I can see:-
Code:
Private Sub Form_Open(Cancel As Integer)
If MsgBox("Continue to Transfer Data or Cancel ?", vbOKCancel) = vbOK Then
' Do the data transfer options here
Else
    ' Cancel Open Event
    Cancel = True
End If

End Sub


'ope-that-'elps.

G LS




As for
QFTD: "If your washing powder got your whites whiter than white and your colours brighter than ever..why do we need a new one? Whats next nuclear white?"

How about "NewClear White"

- I'll get my coat. ..
 
For what you are trying to accomplish, I don't think you can use the CancelEvent operation. If memory serves me right, Access is pretty selective about how to use this operation.

Instead, use the sub/function that you open the form with and control the action of the new form from within your original form. Example:

Form1

cmdButton_Click()

Dim irepsonse as Integer
Docmd.Openform "MyNewForm"
If forms("MyNewForm").NewRecord then
iresponse = msgbox("Close?",vbYesNo, "Title")
If iresponse = vbYes then
docmd.Close acform,"MyNewForm"
End if
End if
End Sub

So, essentially, you are controlling the actions of the form from remote.

Gary
gwinn7
A+,Network+
 
The code is actually running from the OnCurrent event as I need it to run not just when the user opens the form but when he moves to a new record in that form.

The sequence should be as follows:

A) User clicks button on FormA to open FormB or user moves to a new record on already open FormB

B) FormB opens or moves to new record.

C) 'YesNoCancel' Message box opens

D) If 'Cancel' FormB closes and user is taken back to FormA

E) If 'Yes' new record in FormB is filled with info from FormA.

F) If 'No' FormB is opened blank.

The code I have is as follows:

Function ContInsrt()
On Error GoTo Err_ContInsrt

Dim stDocName As String
Dim intResult As Integer

stDocName = MyForm

If stDocName.NewRecord Then

If intResult = MsgBox("Are the Contact details the same as the Site details?", vbYesNoCancel, "Detail confirmation") = vbCancel Then
DoCmd.Close
End

ElseIf intResult = vbYes Then
Call Insert_Details
Else
End If
End If

Exit_ContInsrt:
Exit Function

Err_ContInsrt:
MsgBox Error$

Resume Exit_ContInsrt

End Function

Anything look wrong to you? I've been studying this bit of code for so long I can't even see the obvious.

Thanks.

As For

'NewClear White'

Ouch
:)
 
P.S. LittleSmudge, how do you do italics in your post?

Thanks
 
You might want to specify what form you are closing with the close command.

i.e.

docmd.close acform, "formA"
 
Thanks wkendrvr but, following gwinns' example above, I just have. Doesn't work I'm afraid.
 
Easy Qs first
Start italics with [ then i then ] and then italics with [ then /i then ]
Underline - replace i with u
Bold replace i with b


Okay then : - the Ugly "Close this Form" method ( But it works )

Replace your one line:-
DoCmd.Close

with
Me.TimerInterval = 1


And add this code to the On_Timer event of FormB
Private Sub Form_Timer()
DooCmd.Close
End Sub

If you have a lot of code running in the OnCurrent event after your Function ContInsrt() then you might need to increase the TimerInterval.
If you increase it to 10 or 100 it won't really matter ( Timer Interval is in thousanths of a second )


'ope-that-'elps.

G LS

 
Abraca - blinkin - dabra! It works, thank you.

Ugly 'Close this Form' method is a good name for it. There is a bit of a flicker when you press 'cancel'. But hey, it does the job so who cares?!

Thanks to everyone. Another problem solved.

Ta,

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top