php Break command in Visual Basic

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In php "break" ends execution of the current for, foreach, while, do-while or
switch structure.

In a form I have a Command Button to execute a couple of database commands.
In the top of the coding of the button I added:

If IsNull(Me.cboName) Then
MsgBox "All fields are required"
End If

I want to add a sort of Break command just after the MsgBox to stop all
other commandlines under the Command Button.

Anyone an idea?
 
Hi Jochem,

VBA has Exit Sub, Exit Function, Exit Do, Exit For and so on. Or you
could use

If IsNull(...
MsgBox ...
Else
'do what's required
...
End If

You might want to add
cboName.SetFocus
after the MsgBox statement.
 
What you'd typically do is use the Else part of the If statement to allow
the rest of your commands to be run.

If IsNull(Me.cboName) Then
MsgBox "All fields are required"
Else

' put the code that's supposed to run if Me.cboName is not Null here

End If

Another approach is to use Exit Sub (or Exit Function) for what you're
referring to as Break, but this has the disadvantage that if there's cleanup
that needs to be done at the end of the routine, it'll be bypassed.
 
Thanks guys! You are a great help to the project here (terminal project)!

I used:

If IsNull(Me.cboName) Then
MsgBox "All fields are required"
Else
' put the code that's supposed to run if Me.cboName is not Null here
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top