Multiple Conditions.....

ardy

Registered User.
Local time
Today, 00:25
Joined
Sep 24, 2012
Messages
98
Hello All.....
Can somebody tell me how to do multiple conditions, Nested....I have 6 conditions that i like to check,

Code:
if (condition-1) And
             (condition-2) And
             (condition-3) And
             (condition-4) And
             (condition-5 ) And
             (condition-6) Then
      MsgBox "Some Text"
         Else
             Some Code
End If

Conditions are all checking the input boxes 6 of them......

Code:
varResult1 = IIf(Nz(ctl1.Value) = vbNullString, _
            "No value For First Name", "Value is " & ctl1.Value & ".")

any help is appreciated........
 
Can you explain a little more about what you are trying to do. It sounds like you want to check that all 6 controls(text boxes?) on a form have some data entered.
 
Yes.....That is correct...... The form has more boxes but I just need to make sure they have at minimum the 6 that i want........ I have code that is probably not very efficient but it works, I just need to place the condition on it so it they don't the form let them knows that i need the info.....
Code:
Private Sub btn_CopyNewCustomer_Click()

' Copying information from f_New_Customer Form using Copy Information Crating New Case Button
' to Customer_Call Form.

Dim well As String
Dim WellLookUp As String
Dim frm As Form

Dim ctl1, ctl2, ctl3, ctl4, ctl5, ctl6 As Control
Dim varResult1, varResult2, varResult3, varResult4, varResult5, varResult6 As Variant


    Set frm = Forms!f_New_Customer  ' pointing to New Customer form.
    
    Set ctl1 = frm!FirstName   ' pointing to First Name.
    Set ctl2 = frm!LastName
    Set ctl3 = frm!Address
    Set ctl4 = frm!City
    Set ctl5 = frm!Phone_1
    Set ctl6 = frm!WellNbr_Dropdwn

' ============  6 conditions ==================================   
       varResult1 = IIf(Nz(ctl1.Value) = vbNullString, _
            "No value For First Name", "Value is " & ctl1.Value & ".")
       varResult2 = IIf(Nz(ctl2.Value) = vbNullString, _
            "No value For Last Name", "Value is " & ctl2.Value & ".")
       varResult3 = IIf(Nz(ctl3.Value) = vbNullString, _
            "No value For Address", "Value is " & ctl3.Value & ".")
       varResult4 = IIf(Nz(ctl4.Value) = vbNullString, _
            "No value For City", "Value is " & ctl4.Value & ".")
       varResult5 = IIf(Nz(ctl5.Value) = vbNullString, _
            "No value For Phone-1", "Value is " & ctl5.Value & ".")
       varResult6 = IIf(Nz(ctl6.Value) = vbNullString, _
            "No value For Well Number: ", "Value is " & ctl6.Value & ".")
' ============================================================================           
            
'  ===============  The Message box letting the user know what is blank and what has data ============  
        MsgBox "First Name:  " & varResult1 & vbCrLf & "Last Name:  " & varResult2 _
        & vbCrLf & "Address:  " & varResult3 & vbCrLf & "City :  " & varResult4 _
        & vbCrLf & "Phone1:  " & varResult5 & vbCrLf & "Well Number: " & varResult6, vbExclamation, "Minimum Information Needed"
        
        Exit Sub
'  ====================================================================================================
  
'  ==============  Code excute if all needed info is there ==============================================
        DoCmd.Close acForm, "f_New_Customer", acSaveYes


    DoCmd.OpenForm "Customer_Call", acNormal, , , acFormAdd, acWindowNormal
 '------- Well Location Address
        Forms!Customer_Call.Tbl_First = Forms!f_New_Customer.FirstName
        Forms!Customer_Call.Tbl_Last = Forms!f_New_Customer.LastName
        Forms!Customer_Call.Tbl_Phone_1 = Forms!f_New_Customer.Phone_1
        Forms!Customer_Call.Tbl_Phone_2 = Forms!f_New_Customer.Phone_2
        Forms!Customer_Call.Tbl_E_Mail = Forms!f_New_Customer.E_mail
        Forms!Customer_Call.streetnumber2 = Forms!f_New_Customer.Address
        Forms!Customer_Call.city2 = Forms!f_New_Customer.City
        Forms!Customer_Call.state2 = Forms!f_New_Customer.State
        Forms!Customer_Call.Tbl_Well_ID = Forms!f_New_Customer.Well_ID
        Forms!Customer_Call.Tbl_Zip2 = Forms!f_New_Customer.Zip
  '------ Mailing Address
        Forms!Customer_Call.streetnumber = Forms!f_New_Customer.W_Address
        Forms!Customer_Call.City = Forms!f_New_Customer.W_City
        Forms!Customer_Call.State = Forms!f_New_Customer.W_State
        Forms!Customer_Call.Tbl_Zip = Forms!f_New_Customer.W_Zip
        Forms!Customer_Call.Tbl_Home_Served = Forms!f_New_Customer.Homes_Served
        Forms!Customer_Call.CheckGPSFY2012 = Forms!f_New_Customer.chk_sch_GPS
        
    DoCmd.Close acForm, "f_New_Customer", acSaveNo
    DoCmd.Close acForm, "f_Customer_Lookup", acSaveYes
    DoCmd.OpenForm "Customer_Call"

 
End Sub
 
Try something like this for each of your variables:
Code:
       If Nz(ctl1.Value, "") = "" Then varResult1 = "No value For First Name"
       Else: varResult1 = "Value is " & ctl1.Value & ".")
 
i think having IIF of IF pritty much dose the same, I need run all the conditions with no messages, then run the massage to the user notifying them of what is missing. if all the conditions come out OK, which it means that they have gave me the info I want, then I can take the info and copy to the next form other wise it exit's the sub and dose nothing..........
 
Your code will come out a lot cleaner if you do something like this:

Code:
If Nz(ctl1.Value, "") = "" Then
    MsgBox "No value For First Name"
    Exit Sub
End If

Then you can lose the message box line and just have the six tests
 
Yes I agree I naturally went there after couple of hour ........ The latest is
Code:
If Nz(ctl1.Value, "") = "" Then
        varResult1 = "No value For First Name"
       Else
       varResult1 = "Value is " & ctl1.Value & "."
       Ok1 = 1
    End If
    If Nz(ctl2.Value, "") = "" Then
        varResult2 = "No value For First Name"
       Else
       varResult2 = "Value is " & ctl2.Value & "."
       Ok2 = 2
    End If
    If Nz(ctl3.Value, "") = "" Then
        varResult3 = "No value For First Name"
       Else
       varResult3 = "Value is " & ctl3.Value & "."
       Ok3 = 3
    End If
    If Nz(ctl4.Value, "") = "" Then
        varResult4 = "No value For First Name"
       Else
       varResult4 = "Value is " & ctl4.Value & "."
       Ok4 = 4
    End If
    If Nz(ctl5.Value, "") = "" Then
        varResult5 = "No value For First Name"
       Else
       varResult5 = "Value is " & ctl5.Value & "."
       Ok5 = 5
    End If
    If Nz(ctl6.Value, "") = "" Then
        varResult6 = "No value For First Name"
       Else
       well = ctl6
       varResult6 = "Value is " & ctl6.Value & "."
       Ok6 = 6
     End If

It seem to be working, now I am trying to do a Loop, My approach as crippled as is to assign a value to each condition, in my case 1 through 6 to match the condition and if I get 21 in the loop condition i move on if not it keeps wanting to have the information, but I need to make sure they have escape from the loop......I made a mistake and tried something with no escape and well you know what happens when you have endless loop:eek:........I have to read more on the loop, I learn best by example, but I am reading as I write......
 
Not exactly sure what you are trying to do here.. I keep reading the first post, then I get distracted.. If you want to check for specific controls on the Form, why not loop through? Set the tags of the controls you wish to verify, say "CheckMe"..

So something like..
Code:
Private Sub btn_CopyNewCustomer_Click()[COLOR=Green]
    ' Copying information from f_New_Customer Form using Copy Information Crating New Case Button
    ' to Customer_Call Form.[/COLOR]

    Dim ctrl As Control, longStr As String
    Dim tmpStr As String
    
    For Each ctrl In Me.Controls
        If ctrl.ControlType = acTextBox And Then ctrl.Tag = "CheckMe"
            If Len(ctrl.Value & vbNullString) = 0 Then
                tmpStr = "No value For " & ctrl.Name
            Else
                tmpStr = "Value is " & ctl2.Value & "."
            End If
            longStr = longStr & tmpStr & vbCrLf
        End If
    Next
    MsgBox longStr
[COLOR=Green]    :
    'Your Code..[/COLOR]
 
That would also work, You have got it, much better shorter cide..... I see the use of tag now...... I keep reading abt it and didn't really understood it...

Thanks
 

Users who are viewing this thread

Back
Top Bottom