If...End if combination logic

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,232
Hi All,
Can anyone help me in below code, to rectify it. Something went wrong in logic.

Situation is, when selecting "Core", submit not happened and when select "Non-Core", submit works.

Also, if on any place we can minimize the code, please do guide / help..
Code:
Private Sub btnsubmit_Click()
Application.ScreenUpdating = False


Dim Cn As New ADODB.Connection
Dim cs As String
Dim rs1 As New ADODB.Recordset
                 
'Case 1
If cmbActivity.Value = "" Or ComboBox1.Value = "" Or TxtCaseID.Value = "" Or TxtEETime.Value = "" Or cmbProjectName = "" Or cmbTaskName.Value = "" Or cmbTaskStatus.Value = "" Then
    MsgBox "Select respective item's"
Else


'case 2
If cmbActivity.Value = "Non-Core" And TxtCaseID.Value = "" And TxtEETime.Value = "" And cmbProjectName = "" And cmbTaskName.Value = "" And cmbTaskStatus.Value = "" Then
If ComboBox1.Value = "" Then
    MsgBox "Select sub non-core activity..!!"
Else
    cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\group$\WNA\Timesheet_Data.accdb"
    Cn.Open cs
    rs1.Open "Table1", Cn, adOpenDynamic, adLockOptimistic
    
    With rs1
    .AddNew
    .Fields("Start Date/Time") = Me.txtstartdate
    .Fields("Closed Date/Time") = DateTime.Now
    .Fields("Activity Type") = Me.cmbActivity
    .Fields("Sub Type") = Me.ComboBox1
    .Fields("Comments") = Me.txtcomm
    .Fields("User name") = Me.LblUname
    .Update
    End With
    
    Set rs1 = Nothing
    Cn.Close
    Set Cn = Nothing
    
    txtstartdate.Value = ""
    cmbActivity.Value = ""
    ComboBox1.Value = ""
    cmbTaskStatus.Value = ""
    txtcomm.Value = ""
    
    MsgBox "Details Updated"
    Call UserForm_Initialize


    Exit Sub




'case 3
If cmbActivity.Value = "Core" Then
If ComboBox1.Value = "" Then
    MsgBox "Select sub core activity..!!"
     If TxtCaseID.Value = "" Then
            MsgBox "Copy-Paste CASE ID from EE Tool"
                If TxtEETime.Value = "" Then
                    MsgBox "Copy-Paste EE Time from EE Tool"
                    If cmbProjectName.Value = "" Then
                        MsgBox "Select Project Name.."
                            If cmbTaskName.Value = "" Then
                                MsgBox "Select Task Name.."
                                    If cmbTaskStatus.Value = "" Then
                                        MsgBox "Select Status of the Task"


Else


    cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\group$\WNA\Timesheet_Data.accdb"
    Cn.Open cs
    rs1.Open "Table1", Cn, adOpenDynamic, adLockOptimistic
    
    With rs1
    .AddNew
    .Fields("Start Date/Time") = Me.txtstartdate
    .Fields("Closed Date/Time") = DateTime.Now
    .Fields("Activity Type") = Me.cmbActivity
    .Fields("Sub Type") = Me.ComboBox1
    .Fields("Case ID") = Me.TxtCaseID
    .Fields("EE Tool TimeDate") = Me.TxtEETime
    .Fields("Project Name") = Me.cmbProjectName
    .Fields("Task Name") = Me.cmbTaskName
    .Fields("Task Status") = Me.cmbTaskStatus
    .Fields("Comments") = Me.txtcomm
    .Fields("User name") = Me.LblUname
    .Update
    End With
    
    Set rs1 = Nothing
    Cn.Close
    Set Cn = Nothing
    
    txtstartdate.Value = ""
    cmbActivity.Value = ""
    ComboBox1.Value = ""
    TxtCaseID.Value = ""
    TxtEETime.Value = ""
    cmbProjectName.Value = ""
    cmbTaskName.Value = ""
    cmbTaskStatus.Value = ""
    txtcomm.Value = ""
    
    MsgBox "Details Updated"
    Call UserForm_Initialize
        
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If


Application.ScreenUpdating = True
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top