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

Hi Folks, I've created a basic e

Status
Not open for further replies.

remeng

Technical User
Jul 27, 2006
504
0
16
US
Hi Folks,

I've created a basic error check for an button operation in a Power Point "form". This is being called by sub go_click (). I'd like to have the go_click() sub stop if any of the conditions are met for an error message to pop up. Is there a way to do this? I'm just a hack an slash beginner vba user.

Thanks,

Mike

Code:
Private Sub error_check()

' blank option


If Returnable = False And disposable = False Then

    MsgBox "Please select a Packaging Type.  It is currently blank."
    
    End If
    
    If dap = False And fca = False Then
    
        MsgBox "Please select an Incoterm.  It is currently blank."
    
    End If
    
    If warehouse = False And plant = False And tct = False And three_pl = False Then
    
        MsgBox "Please select a Delivery Location.  It is currently blank."
    
    End If
    
    If dap = False And fca = False Then
    
        MsgBox "Please select an Incoterm.  It is currently blank."
    
    End If
    
    If FL01 = False And FL02 = False And FL04 = False And FL05 = False Then
    
        MsgBox "Please select a Flow Type.  It is currently blank."
    
    End If
    
    If repack = False And norepack = False Then
    
        MsgBox "Please select an Internal Repack Strategy.  It is currently blank."

End If

'----------------------------
    
'Incorrect flow to delivery location

    
    
If FL01 = True And plant = False Then
    
    MsgBox "Flow 1 material must be delivered directly to the Plant.  Please select the Direct to Plant (FL01) Delivery Location."
    
    End If
    
If FL01 = False And plant = True Then
    
    MsgBox "Material delivered directly to the Plant must have a FL01 flow.  Please select FL01 as the flow type."
        
    End If
    
If FL04 = True And three_pl = True Then

MsgBox "Material delivered directly to the 3PL must have a FL02 flow.  Please select FL02 as the flow type."

End If
    
'----------------------------

'Flow and Internal Repack

If repack = True And FL02 = True Then

    MsgBox "FL02 material cannot be repacked.  Please select either another flow type or a different Repack Strategy."

End If

If repack = True And FL01 = True Then

    MsgBox "FL01 material cannot be repacked.  Please select either another flow type or a different Repack Strategy."

End If

If three_pl = True And FL01 = True Then


    MsgBox "3PL material cannot be FL01.  Please select a different Flow."

End If


End Sub
 
>button operation in a Power Point "form"

So this'll be a VBA question, rather than VB, so you might be better off posting in forum707
 
Code:
Private Sub go_click()

[blue]If error_check Then Exit Sub[/blue]

....
End Sub

Private [blue]Function[/blue] error_check()[blue] As Boolean[/blue]

If Returnable = False And disposable = False Then
    MsgBox "Please select a Packaging Type.  It is currently blank."
    [blue]error_check = True[/blue]
End If
    
If dap = False And fca = False Then
    MsgBox "Please select an Incoterm.  It is currently blank."
    [blue]error_check = True[/blue]
End If
...
End [blue]Function[/blue]


---- Andy

There is a great need for a sarcasm font.
 
Hi Andy,

I should have also given you this section of code on how I am calling error_check out of go-Click()

is there any modification to your code that I need to know about? Thanks, Mike

Code:
Private Sub go_Click()

Call error_check
 
Your current [tt]error_check[/tt] is a Sub and that is the way to call a Sub.
But, as you can see, I changed your Sub into a Function (which returns a value, in this case a Boolean) so try what I gave you in my previous post and see if it will work.

So, in short:

Code:
Private Sub go_click()
[green]
'Call error_check [/green]
If error_check Then Exit Sub

....
End Sub

Also, for future reference, follow strongm's suggestion :)


---- Andy

There is a great need for a sarcasm font.
 
Er, Andy's code already illustrates his suggested change to your code ..

replace

[tt]Call error_check[/tt]

with

[tt]If error_check Then Exit Sub[/tt]
 
Ah - looks like Andy and I posted at the same time :)
 
Strongm, looks like you are (almost) the ‘fastest hand at the salad bar’ with your replies... :)


---- Andy

There is a great need for a sarcasm font.
 
Thanks guys. It looks like it works. At least I can't generate an error that would cause it not to work at this time anyway.

So what is the difference between Call and Function? I would like to understand what is going on so I can use it properly in the future.

 
Not "difference between Call and Function" but "Sub and Function"

In short, you can (you don't have to) pass arguments to both, but Sub does not return anything, but Function returns a value. It is very handy to know the difference and use both appropriately in your code.

For your testing, you can always do:

Code:
...[blue]
MsgBox "This is a Test"
error_check = True[/blue]
End Function
So this Function will always return True (just for testing)


---- Andy

There is a great need for a sarcasm font.
 
I suspect the question was really about when to use Call and when not to use Call, and what is the difference
 
You may be right, but you do see my approach/understanding remeng's question, right?


---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top