if then elseif problem 
Author Message
 if then elseif problem

I have a form with many controls. When users press the save button, a series of
events should occur in the order I've code it.

For some unknown reason it begins with the first controls [cboCN] and skips
directly to [cboFGC] then directly to End If and continues on with no problem.

This happens inconsistently & I have not been able to track down a pattern.
Other times it works just as the codes are written.

Any help & suggestion is greatly appreciated.

********Code Begin*******
Private Sub cmdSave_Click()
Dim strTitle, strMsg2, strEO As String
strEO = " Enter Opportunities."
strTitle = "Required Data"
If IsNull([cboCN]) Then
  strMsg2 = MsgBox("Select clock No.", vbDefaultButton1, strTitle)
  cboCN.SetFocus
   Exit Sub
 ElseIf IsNull([intRev]) Then
  strMsg2 = MsgBox("Enter revision.", vbDefaultButton1, strTitle)
  intRev.SetFocus
   Exit Sub
 ElseIf IsNull([intOLD]) Then
  strMsg2 = MsgBox("Enter Offload Date.", vbDefaultButton1, strTitle)
  intOLD.SetFocus
    Exit Sub
 ElseIf txtFN Like "" Then
  strMsg2 = MsgBox("Enter Figure Number.", vbDefaultButton1, strTitle)
  txtFN.SetFocus
    Exit Sub
 ElseIf txtTF Like "" Then
  strMsg2 = MsgBox("Enter True Figure.", vbDefaultButton1, strTitle)
  txtTF.SetFocus
    Exit Sub
 ElseIf txtDN Like "" Then
  strMsg2 = MsgBox("Enter Drawing Number.", vbDefaultButton1, strTitle)
  txtDN.SetFocus
    Exit Sub
 ElseIf txtAN Like "" Then
  strMsg2 = MsgBox("Enter Art Number.", vbDefaultButton1, strTitle)
  txtAN.SetFocus
    Exit Sub
 ElseIf txtAssy Like "" Then
  strMsg2 = MsgBox(" Enter Assembly Number.", vbDefaultButton1, strTitle)
  txtAssy.SetFocus
    Exit Sub
 ElseIf cboFGC Like "" Then
  strMsg2 = MsgBox("Enter Feature Group Code.", vbDefaultButton1, strTitle)
  cboFGC.SetFocus
    Exit Sub
 ElseIf txtFVC Like "" Then
  strMsg2 = MsgBox(" Enter Feature Variation Code.", vbDefaultButton1,
strTitle)
  txtFVC.SetFocus
    Exit Sub
 ElseIf fraPILL = 1 Then
    'PL
    If IsNull([intIMPNOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intIMPNOp.SetFocus
        Exit Sub
    ElseIf IsNull([intIMPN2DeOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intIMPN2DeOp.SetFocus
        Exit Sub
    ElseIf IsNull([intDPNOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intDPNOp.SetFocus
        Exit Sub
    ElseIf IsNull([intIARefS2Op]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intIARefS2Op.SetFocus
        Exit Sub
    ElseIf IsNull([intTAMisOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intTAMisOp.SetFocus
        Exit Sub
    ElseIf IsNull([intIFNOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intIFNOp.SetFocus
        Exit Sub
    ElseIf IsNull([intIQOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intIQOp.SetFocus
        Exit Sub
    ElseIf IsNull([intIFTOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intIFTOp.SetFocus
        Exit Sub
    ElseIf IsNull([intIKtIDOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intIKtIDOp.SetFocus
        Exit Sub
    ElseIf IsNull([intIFIDOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intIFIDOp.SetFocus
        Exit Sub
    End If

 'ILL

ElseIf fraPILL = 2 Then
    If IsNull([intATMisOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intATMisOp.SetFocus
        Exit Sub
    ElseIf IsNull([intILOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intILOp.SetFocus
        Exit Sub
    ElseIf IsNull([intAOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intAOp.SetFocus
        Exit Sub
    ElseIf IsNull([intLOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intLOp.SetFocus
        Exit Sub
    ElseIf IsNull([intOOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intOOp.SetFocus
        Exit Sub
    ElseIf IsNull([intCGMOp]) Then
      strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
      intCGMOp.SetFocus
        Exit Sub
    End If
End If

DoCmd.SetWarnings False
DoCmd.OpenQuery "a_qMain"
strMsg2 = MsgBox("Data Saved", vbDefaultButton1)
cboCN = ""
Requery
intRev = Null
intOLD = Null
txtFN = ""
txtTF = ""
txtDN = ""
txtAN = ""
txtAssy = ""
cboFGC = ""
txtFVC = ""
intIMPND = Null
intIMPNOp = Null
intIMPN2DeD = Null
intIMPN2DeOp = Null
intDPND = Null
intDPNOp = Null
intIARefS2D = Null
intIARefS2Op = Null
intTAMisD = Null
intTAMisOp = Null
intIFND = Null
intIFNOp = Null
intIQD = Null
intIQOp = Null
intIFTD = Null
intIFTOp = Null
intIKtIDD = Null
intIKtIDOp = Null
intIFIDD = Null
intIFIDOp = Null
intATMisD = Null
intATMisOp = Null
intILD = Null
intILOp = Null
intAD = Null
intAOp = Null
intLD = Null
intLOp = Null
intOD = Null
intOOp = Null
intCGMD = Null
intCGMOp = Null
txtNotes = ""
End Sub

******Code End*******



Tue, 07 Jan 2003 03:00:00 GMT  
 if then elseif problem
Hello,
        After a quick look at your code it looks like it finds a null at the
first check then it will activate the messagebox then it will exit the
sub as you noted. However I am a bit confused,

1.As far as I know the MsgBox does not return a string.
2.I assume that you have declared the int variables as Integers? If so
they will not accept Null so if your code ever gets that far you will
get type mismatch errors.

I would suggest that you drop the multiple if then else construct and
use Select Case it will be easier to understand.

If you wish you can e-mail a sample of your DB and I will try to help
you
Regards
Ian Pratt

Quote:

> I have a form with many controls. When users press the save button, a series of
> events should occur in the order I've code it.

> For some unknown reason it begins with the first controls [cboCN] and skips
> directly to [cboFGC] then directly to End If and continues on with no problem.

> This happens inconsistently & I have not been able to track down a pattern.
> Other times it works just as the codes are written.

> Any help & suggestion is greatly appreciated.

> ********Code Begin*******
> Private Sub cmdSave_Click()
> Dim strTitle, strMsg2, strEO As String
> strEO = " Enter Opportunities."
> strTitle = "Required Data"
> If IsNull([cboCN]) Then
>   strMsg2 = MsgBox("Select clock No.", vbDefaultButton1, strTitle)
>   cboCN.SetFocus
>    Exit Sub
>  ElseIf IsNull([intRev]) Then
>   strMsg2 = MsgBox("Enter revision.", vbDefaultButton1, strTitle)
>   intRev.SetFocus
>    Exit Sub
>  ElseIf IsNull([intOLD]) Then
>   strMsg2 = MsgBox("Enter Offload Date.", vbDefaultButton1, strTitle)
>   intOLD.SetFocus
>     Exit Sub
>  ElseIf txtFN Like "" Then
>   strMsg2 = MsgBox("Enter Figure Number.", vbDefaultButton1, strTitle)
>   txtFN.SetFocus
>     Exit Sub
>  ElseIf txtTF Like "" Then
>   strMsg2 = MsgBox("Enter True Figure.", vbDefaultButton1, strTitle)
>   txtTF.SetFocus
>     Exit Sub
>  ElseIf txtDN Like "" Then
>   strMsg2 = MsgBox("Enter Drawing Number.", vbDefaultButton1, strTitle)
>   txtDN.SetFocus
>     Exit Sub
>  ElseIf txtAN Like "" Then
>   strMsg2 = MsgBox("Enter Art Number.", vbDefaultButton1, strTitle)
>   txtAN.SetFocus
>     Exit Sub
>  ElseIf txtAssy Like "" Then
>   strMsg2 = MsgBox(" Enter Assembly Number.", vbDefaultButton1, strTitle)
>   txtAssy.SetFocus
>     Exit Sub
>  ElseIf cboFGC Like "" Then
>   strMsg2 = MsgBox("Enter Feature Group Code.", vbDefaultButton1, strTitle)
>   cboFGC.SetFocus
>     Exit Sub
>  ElseIf txtFVC Like "" Then
>   strMsg2 = MsgBox(" Enter Feature Variation Code.", vbDefaultButton1,
> strTitle)
>   txtFVC.SetFocus
>     Exit Sub
>  ElseIf fraPILL = 1 Then
>     'PL
>     If IsNull([intIMPNOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intIMPNOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intIMPN2DeOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intIMPN2DeOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intDPNOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intDPNOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intIARefS2Op]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intIARefS2Op.SetFocus
>         Exit Sub
>     ElseIf IsNull([intTAMisOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intTAMisOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intIFNOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intIFNOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intIQOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intIQOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intIFTOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intIFTOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intIKtIDOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intIKtIDOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intIFIDOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intIFIDOp.SetFocus
>         Exit Sub
>     End If

>  'ILL

> ElseIf fraPILL = 2 Then
>     If IsNull([intATMisOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intATMisOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intILOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intILOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intAOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intAOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intLOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intLOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intOOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intOOp.SetFocus
>         Exit Sub
>     ElseIf IsNull([intCGMOp]) Then
>       strMsg2 = MsgBox(strEO, vbDefaultButton1, strTitle)
>       intCGMOp.SetFocus
>         Exit Sub
>     End If
> End If

> DoCmd.SetWarnings False
> DoCmd.OpenQuery "a_qMain"
> strMsg2 = MsgBox("Data Saved", vbDefaultButton1)
> cboCN = ""
> Requery
> intRev = Null
> intOLD = Null
> txtFN = ""
> txtTF = ""
> txtDN = ""
> txtAN = ""
> txtAssy = ""
> cboFGC = ""
> txtFVC = ""
> intIMPND = Null
> intIMPNOp = Null
> intIMPN2DeD = Null
> intIMPN2DeOp = Null
> intDPND = Null
> intDPNOp = Null
> intIARefS2D = Null
> intIARefS2Op = Null
> intTAMisD = Null
> intTAMisOp = Null
> intIFND = Null
> intIFNOp = Null
> intIQD = Null
> intIQOp = Null
> intIFTD = Null
> intIFTOp = Null
> intIKtIDD = Null
> intIKtIDOp = Null
> intIFIDD = Null
> intIFIDOp = Null
> intATMisD = Null
> intATMisOp = Null
> intILD = Null
> intILOp = Null
> intAD = Null
> intAOp = Null
> intLD = Null
> intLOp = Null
> intOD = Null
> intOOp = Null
> intCGMD = Null
> intCGMOp = Null
> txtNotes = ""
> End Sub

> ******Code End*******



Tue, 07 Jan 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. If..ElseIf..Else problem

2. Problems with a simple if-elseif

3. nested if/elseif statements

4. If Then ElseIf Statements

5. Select case/if then elseif

6. Elseif Statements

7. Need confirmation about ElseIf statement

8. Select Case Vs If - ElseIf

9. If Then ElseIf the solution to this bug?

10. Elseif Condition in Crystal Reports 4.6

11. If-Then-Elseif

12. If..Elseif vs. Select case

 

 
Powered by phpBB® Forum Software