Problem with calling a case statement from a case statement
i am trying to call a case statement from a case statement..it is throwing an error
if u can tell me where i am getting wrong
Select Case strOper
Case "Search for Product"
.ClearToQuery
.SetViewMode 3
.SetSearchSpec "Name", strProduct
.ExecuteQuery 1
strInstep = "Step 5:Checking for Product Name existence"
If .FirstRecord = strProduct Then
Goto Case "Search for Cost List"---------------it throws error here
Re: Problem with calling a case statement from a case statement
Hi poshyradha
It is better to send more complete code snippets and within code tags.
anyway, using goto is discouraged. It causes what is know as spaghetti code, the code that is hard to follow and trace.
you better refactor your code and move the actions in Case "Search for Product" block to another function or method and call it.
Re: Problem with calling a case statement from a case statement
Using Goto is not a good practice. It seems you want to execute another block of statements from the same case. As suggested refactor your code and also, post the complete code block, not just the line that is giving an error.
Re: Problem with calling a case statement from a case statement
Poshyradha
Do you have a CASE called "Search for Cost List"?
Or just "Cost List"?
Re: Problem with calling a case statement from a case statement
[ cleaned ]
Folks, it is important to post content relevant to the topic under discussion.
To discuss issues that donot concern the thread, please use "Private Messaging". If you have problems, approach a Moderator.
Regards,
Siddhartha
Re: Problem with calling a case statement from a case statement
Well first of all your using the Goto Incorectly...
You need to define a Line Lable for the goto to jump too..
Code:
Select Case strOper
Case "Search for Product"
......
.ClearToQuery
.SetViewMode 3
.SetSearchSpec "Name", strProduct
.ExecuteQuery 1
strInstep = "Step 5:Checking for Product Name existence"
If .FirstRecord = strProduct Then
'Goto Case "Search for Cost List"---------------it throws error here
Goto Next_Step
.....
Case "Search for Cost List"
Next_Step:
.......
You define lables in code by preceeding (err following) them with a ':' ..
Gremmy...
Re: Problem with calling a case statement from a case statement
Quote:
Originally Posted by GremlinSA
You define lables in code by preceeding them with a ':' ..
Gremmy...
You define labels in code with a ':' after the label text.
Code:
'...
Exit Sub
ErrorOccured:
MsgBox Err.Description
'...
Starting with a ':' makes VB believe it's a blank statement.
Re: Problem with calling a case statement from a case statement
Starting with a : is the same as the LINE CONTINUATION symbol. It's treated as nothing other than a new statement. It's not ignored.
Ending with a ":" makes it a line label, and moves it to the far left.
Code:
Option Explicit
Private Sub Form_Load()
Dim a
: a = 2
MsgBox a
End Sub
Re: Problem with calling a case statement from a case statement
Ooooppss..
Quote:
Originally Posted by dglienna
Ending with a ":" makes it a line label, and moves it to the far left.
You are so right...
I dont usually use line lables... and got a little mixed up... I'm too stupid...
Gremmy...