stopping the code

Ankarn

Registered User.
Local time
Today, 13:20
Joined
Jul 4, 2008
Messages
81
I have a fairly long if-code.

some places in that if, a form should open

If Something Then
DoCmd.OpenForm
End If

The thing is, depending of what i do in the new form that i open, i would continue the code, or not. Not continue that if, that wouldnt make sense, but i have something that should happen later.

Is there any way of stopping code?
 
If you open the form as Dialog (see the properties of the openform) the code should stop.
You can test this by putting a msgbox right after the openform.
 
but can i then make it start again if i press a certain button in the new form that i've opened?
 
Hi,

you can try to pass a value from the new opened form, back to the original one via openargs, and based on the value passed you run the code that you require.
 
With a dialog form the code will be frozen untill the form is closed.
 
Openarg is part of the openform statement,in the openargs you can put ANYTHING you like and use Me.Openargs in the "opened form" to retrieve that "anything" to use it to your benifit.

It is often used to pass Keys or stuff between forms
 
but can i then make it start again if i press a certain button in the new form that i've opened?

that's why i suggested using the openargs because from the above quote it seems that you do not only wish to freeze the code, but there may be a situation where you might want to re-run the code.

if you search this forum about openargs, there are several threads covering the topic, as i learnt about it myself from this forum.
 
I found a way that made me not have to stop the code, but now it complains about the fact that i stopped the last operation. Runtime error 2001. Why is that? is it really a problem that i open a new form before a code is done running?
 
if in the original form you were creating a record try to save it before you open the other form by putting something like DoCmd.RunCommand acCmdSaveRecord before your open form command.
 
It's still the case.

Code:
If statInt > 0 Then
    If sendInt > 0 Then
        If IsNull(Me.Send) Then
            sMsg = sMsg & "Ny Status: " & DLookup("[Status]", "Status", "[StatusID] =" & Me.NyStatus)
        Else
            sMsg = sMsg & "Ny Status: " & DLookup("[Status]", "Status", "[StatusID] =" & Me.NyStatus) & " og Adressat: " & DLookup("[Mottaker]", "Mottaker", "[MottakerID] =" & Me.Send)
            If MsgBox("Legge til adresse/kommentar?", vbQuestion + vbYesNo, "Adresse") = vbYes Then
                DoCmd.RunCommand acCmdSaveRecord
                DoCmd.OpenForm "Adresse"
            End If
        End If
    Else
        sMsg = sMsg & "Ny Status: " & DLookup("[Status]", "Status", "[StatusID] =" & Me.NyStatus)
    End If
 
Me.Send = Null
Me.NyStatus = Null
Forms!MainSearch!Results.Requery
Me.Sendt.Requery
Me.Status.Requery
Me.Requery
Me.Refresh
Me.Repaint
Forms!MainSearch!Results.Form.Requery
 
End If

There are things happening before this as well, but this is the only place where OpenForm is used.
 
Hi,

i had something similar that troubled me. i made a case statement to control the decisions-

MyCode()
'code here until an answer is required via msgbox
Call MyMessageCode
End Sub

let the mesagebox handle the decision

MyMessageCode()
Dim Answer As Integer
Dim strOne As String
Dim strTwo As String
Dim strThree As String


Answer = MsgBox(" Your text ", vbYesNoCancel)

Select Case Answer
Case vbYes
'Code to run if answer is Yes
Call MessageYes
Case vbNo
'Code to run if answer is No
Call MessageNo
Case vbCancel
'Code to run if cancel is pressed
End Select
End Sub

Sub MessageYes()
'code for the YES answer
End Sub

Sub MessageNo()
'code for the NO answer
End Sub

Sub MessageCancel()
'Code for the CANCEL answer
'most likely, the continuation of the code until another decision is to be made


this works fine for me and i placed varius decision type codes in to go where i needed to go.

regs,

Nigel
 
Well.. i understand what you're doing there, but i need it to be dependent on what i do in another form, i cant use MsgBox for it.
 
Well I presume that form is storing data someplace?? So you stop your code untill the form is closed then pick up the data from the table and continue...
 

Users who are viewing this thread

Back
Top Bottom